shell script error expecting "do"
41,411
Solution 1
I suspect line endings.
Try:
hexdump -C yourscript.sh
And look for 0d 0a
sequences. You can strip \r
(0d
) with the tr
command:
cat yourscript.sh | tr -d '\r' >> yournewscript.sh
Solution 2
Give this a try:
#!/bin/sh
while [ true ]
do
echo "WTF"
done
Please pay special attention to the spaces in the line 'while [ true ]'
Related videos on Youtube
Comments
-
Jordan almost 3 years
#!/bin/sh while true ; do echo "WTF" done
This is giving a syntax error: syntax error: unexpected end of file (expecting "do")
I also tried:
#!/bin/sh while : do echo "WTF" done
-
jwir3 about 13 yearsAh, whoops... beat me to it. ;)
-
Jordan about 13 yearsI see 0d 0a sequences but your line to strip them out with the tr command didn't work for me. I used vi after that didn't work and its working fine now! thanks
-
Ofer about 13 yearsNo problem. If you are uploading the script to your linux/unix box via FTP, you can select ascii/text format, and FTP will handle the end of line conversion for you. If, on the other hand, you are creating the file some other way, tr is a good tool to strip unwanted characters.
-
Josh Graham about 5 years@Jordan That command did not work for me if I tried to name the new script the same name as the old script. If you use a different name, delete the old file, then rename the new file to the old file name it will work.
-
viveknaskar almost 4 yearsThis command worked for me as I had messed up the line endings. Thanks!