shell Syntax error: "(" unexpected错误

原文链接:> https://www.zhoubotong.site/post/89.html

执行一个正常的普通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 即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章