shell 編程 錯誤 [: missing ]

想學習腳本編程,就看着書寫了一個


#!/bin/sh
#test whether the file exists
filename=$1
if [ -x "$filename"]
then
    echo "$filename exists."
else
    echo "$filename doesn't exist."
fi

exit


保存爲fileexist.sh,改權限,運行,結果報錯。

./fileexist.sh: 3: [: missing ]


問題出在哪裏?[ ]裏面的內容與中括號之間得有空格

我要是不動手,永遠也發現不了這一點啊


#!/bin/sh
#test whether the file exists
filename=$1
if [ -x "$filename" ]
then
    echo "$filename exists."
else
    echo "$filename doesn't exist."
fi

exit


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章