shell Syntax error: "(" unexpected错误
执行一个正常的普通do.sh脚本:
#!/bin/bash # 定义函数 function func() { n=100 } # 调用函数 func echo $n #输出函数内部的变量
使用 ./do.sh和 source do.sh 或者 . do.sh 均能正常执行,问题如下:
uos@uos-PC:~/Desktop$ sh do.sh do.sh: 3: do.sh: Syntax error: "(" unexpected
什么鬼?经查发现是sh 与 bash 有些地方不兼容导致,直接 bash do.sh 即可。