Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell script error expecting "do"

Tags:

linux

bash

shell

#!/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
like image 976
Jordan Avatar asked Mar 30 '11 20:03

Jordan


2 Answers

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
like image 86
Aaron H. Avatar answered Nov 14 '22 19:11

Aaron H.


Give this a try:

#!/bin/sh
while [ true ]
do
    echo "WTF"
done

Please pay special attention to the spaces in the line 'while [ true ]'

like image 31
Eric Bernier Avatar answered Nov 14 '22 20:11

Eric Bernier