同一脚本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 $*
[email protected]:~/shells$ ll 8_5_1.sh
-rw-r--r-- 1 yao yao 302 4月 27 11:13 8_5_1.sh
[email protected]:~/shells$ sh 8_5_1.sh
8_5_1.sh: 1: 8_5_1.sh: Syntax error: "(" unexpected
把脚本权限修改为755后,脚本正常执行
[email protected]:~/shells$ chmod 755 8_5_1.sh
[email protected]:~/shells$ ll 8_5_1.sh
-rwxr-xr-x 1 yao yao 302 4月 27 11:13 8_5_1.sh*
[email protected]:~/shells$ ./8_5_1.sh
usage:./8_5_1.sh url
原文地址:https://www.cnblogs.com/yaowensheng/p/10778181.html
时间: 2024-10-08 03:53:55