I'm trying to run my shell script on Linux (Ubuntu).
It's running correctly on MacOS, but on Ubuntu it doesn't.
#!/usr/bin/env bash
while true
do
node Client/request -t 10.9.2.4 -p 4400 --flood
done
Ubuntu output this error for running: sh myScript.sh:
Syntax error: end of file unexpected (expecting "do")
- Why is there any difference between them, since both of them are running by Bash? How can I avoid future errors caused by their differences?
I tried
cat yourscript.sh | tr -d '\r' >> yournewscript.shas related question was suggested to do, and alsowhile [ true ]. The commandhexdump -C util/runner.shresult is:00000000 23 21 2f 75 73 72 2f 62 69 6e 2f 65 6e 76 20 62 |#!/usr/bin/env b| 00000010 61 73 68 0d 0a 0d 0a 77 68 69 6c 65 20 5b 20 74 |ash....while [ t| 00000020 72 75 65 20 5d 0d 0a 64 6f 0d 0a 20 20 20 6e 6f |rue ]..do.. no| 00000030 64 65 20 43 6c 69 65 6e 74 2f 72 65 71 75 65 73 |de Client/reques| 00000040 74 20 2d 74 20 31 39 32 2e 31 36 38 2e 30 2e 34 |t -t 192.168.0.4| 00000050 31 20 2d 70 20 34 34 30 30 20 2d 2d 66 6c 6f 6f |1 -p 4400 --floo| 00000060 64 0d 0a 64 6f 6e 65 0d 0a |d..done..| 00000069
"\r\n"), and not POSIX line-endings (plain LF,"\n"). That might have something to do with your problem.while).tr -d '\r' < yourscript.sh > yournewscript.shthenbash yournewscript.sh