0
for循環shell腳本語法錯誤:意外字(預期 「DO」)for循環shell腳本語法錯誤:意外字(預期 「做」)
#!/bin/sh PRO="a t d e k " for file in $PRO do #this will be line 6 echo $file done
輸出:6號線:語法錯誤:意想不到的詞(預期「做」)
for循環shell腳本語法錯誤:意外字(預期 「DO」)for循環shell腳本語法錯誤:意外字(預期 「做」)
#!/bin/sh PRO="a t d e k " for file in $PRO do #this will be line 6 echo $file done
輸出:6號線:語法錯誤:意想不到的詞(預期「做」)
發現了一個^ M,當我在vi編輯器打開它。它幫助我解決了這個問題。
所以這是一些像這樣的事情時,我在vi編輯器中打開它
for file in $PRO
do^M
echo $file
done^M
你可能在你的文件DOS行結束使用DOS2UNIX的命令,從而使shell看到'do \ r'而不是'do'。 – chepner
我如何驗證? –
@chepner,是的..當我在vi編輯器中打開它時找到了一個^ M。它幫助我解決了這個問題。後面將參照使用DOS2UNIX的命令http://linuxcommand.org/man_pages/dos2unix1.html的 –