想学习脚本编程,就看着书写了一个
#!/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