当前位置: 动力学知识库 > 问答 > 编程问答 >

linux - shell script error expecting "do"

问题描述:

#!/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

网友答案:

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
网友答案:

Give this a try:

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

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: