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 即可。

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