想學習腳本編程,就看着書寫了一個
#!/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