2015-04-25 68 views
-1

這裏是shell腳本代碼,當我在CentOS的6.6使用,它將有兩個錯誤消息....Centos的6.6 shell腳本-syntax錯誤附近意外的標記

./script12.bash: line 11: syntax error near unexpected token `$1' 
./script12.bash: line 11: `case $1 in' 

你能幫我找到錯誤?

#! /bin/bash 
num=0 
until [ "$num" -eq 30 ] 
do 
   echo -n "Please input a number here : " 
   read num 

   if [ "$num" -gt 30 ] ; then 
    echo "$num" is too big , try again. 
    echo 
   elif [ "$num" -eq 30 ] ; then 
    echo BINGO !! you got it. 
   else 
    echo "$num" is too small , try again. 
    echo 
   fi 
done 
+1

嘗試運行第11行的腳本改爲'echo「BINGO !!看起來,'!!'被評估爲歷史擴展,儘管該功能應該在非交互式shell中關閉。你可能會以某種方式打開它,但是提出的編輯應該有助於確定是否是這種情況。 – chepner

+1

錯誤消息引用'case $ 1 in',這在您發佈的代碼中不存在。錯誤來自其他地方。另外,你的shebang行中不應該有空格(它應該是'#!/ bin/bash')。 –

+0

@Jordan:那個空間是好的(只要是正常的ascii空間就行了) – Mat

回答

0

不知道如何,但你的腳本中包含奇怪的空白字符,十六進制編輯器顯示ASCII碼80個字符,這似乎混淆了慶典。當用普通空格(ASCII碼20)替換它們時,以下工作:

#!/bin/bash 

num=0 
until [ "$num" -eq 30 ] 
do 
    echo -n "Please input a number here : " 
    read num 

    if [ "$num" -gt 30 ] ; then 
     echo "$num" is too big , try again. 
     echo 
    elif [ "$num" -eq 30 ] ; then 
     echo BINGO !! you got it. 
    else 
     echo "$num" is too small , try again. 
     echo 
    fi 
done 
相關問題