原文鏈接:> 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 即可。