This morning I’ve been playing “spot the difference” – a simple enough task: use a bash shell script to get 2 strings from a user (first name and second name) and then evaluate whether the 2 strings are the same or different. I had a template for the script and everything from the edX course, so it wasn’t even like I had to think very hard (did that make me lazy??), and yet this persistent error “command not found”:
Eventually, with the words of Zed A. Shaw ringing in my head, I decided to do a letter by letter comparison of my script vs the given script – and the error immediately came to light: YES, those two spaces do make a difference!
I feel a bit like a chump chop – but also I’m kind of glad that I hit this road bump because I’m not likely to forget these 2 particular lessons in a hurry:
- String comparisons require spaces before and after the brackets
- If results are unexpected then “think detail” because precision IS required
Zed A. Shaw recommends reading each line of code backwards to aid in finding the mistakes because otherwise the mind tends to just see what it expects to see. Indeed 🙂
There are more examples like this so be careful! In Python it doesn’t matter, but with bash it certainly does: