同一脚本sh 脚本名 执行时报Syntax error: "(" unexpected;而./脚本名执行不报错,为什么呢
脚本内容如下:
function usage(){
echo "usage:$0 url"
exit
} function check_url(){
wget --spider -q -o /dev/null --tries= -T $
if [ $? -eq ]
then
echo "$1 is ok"
else
echo "$1 is not ok "
fi
} function main(){
if [ $# -ne ]
then
usage
fi
check_url $
} main $*
yao@linux:~/shells$ ll 8_5_1.sh
-rw-r--r-- 1 yao yao 302 4月 27 11:13 8_5_1.sh
yao@linux:~/shells$ sh 8_5_1.sh
8_5_1.sh: 1: 8_5_1.sh: Syntax error: "(" unexpected
把脚本权限修改为755后,脚本正常执行
yao@linux:~/shells$ chmod 755 8_5_1.sh
yao@linux:~/shells$ ll 8_5_1.sh
-rwxr-xr-x 1 yao yao 302 4月 27 11:13 8_5_1.sh*
yao@linux:~/shells$ ./8_5_1.sh
usage:./8_5_1.sh url