You're on Cygwin, right?
As I said in the comment, when I copy and paste your script and run it on my system, it works; output
true end
But when I change the line ending from Unix style '\n' to Windows style '\r\n' , I get the same error.
At the end of a line in the style of Windows bash, then is not displayed; he sees a command named then\r . It never tries to execute it because it scans the then or fi match for the if keyword (which it recognized because it is not at the end of the line).
Make sure your shell scripts use Unix-style line endings.
source share