同一脚本sh 脚本名 执行时报Syntax error: "(" unexpected;而./脚本名执行不报错,为什么呢
脚本内容如下:
function usage(){ echo "usage:$0 url" exit 1 } function check_url(){ wget --spider -q -o /dev/null --tries=1 -T 5 $1 if [ $? -eq 0 ] then echo "$1 is ok" else echo "$1 is not ok " fi } function main(){ if [ $# -ne 1 ] then usage fi check_url $1 } main $*View Code
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