[Expanded from my comment...] The script file apparently has DOS-style line endings (i.e. carriage return followed by linefeed, instead of just linefeed). This confuses the shell greatly, since it sees the carriage return as part of the command. The giveaway is that first error message:
: not found.sh: 2: graphhopper.sh:
What's actually happened is it printed the error message "graphhopper.sh: 2: graphhopper.sh: ^M: not found" (where the ^M is actually a carriage return); when the terminal sees the ^M it goes back to the beginning of the line, and prints the end of the error message over top of the beginning.
One of the other effects this has is that the shell can't recognize keywords at the end of lines. When it sees a line like:
if [ ${OSM_FILE: -4} == ".pbf" ]; then^M
...it thinks then^M
a regular command, not the end of the condition part of the if
command, so it keeps looking for a then
. But the else
command seems to have some spaces at the end:
else ^M
...which means the shell does recognize the else
keyword and get very confused about what it's doing in the middle of the condition part of the if
.
So what can you do about it? There's almost certainly a command for it; I'm used to dos2unix
, but apparently ubuntu doesn't have that, instead the "tofrodos" package includes the command fromdos
(see here). Or, you can do it with perl:
perl -pi -e 's/\r//g' graphhopper.sh
Your text editor may also be able to save in unix (rather than DOS) format. Speaking of which, you should either switch your text editor to unix mode, or find a different text editor for scripting.