bash 语法错误:“(”意外(期望“完成”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29287474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:39:57  来源:igfitidea点击:

Syntax error: "(" unexpected (expecting "done")

bashshell

提问by Adam_G

I have a very simple shell script which I'm using to loop through directories, and call another shell script. I wrote it on my local machine (OSX running bash 3.2), and am using it on a remote server running bash 4.2.

我有一个非常简单的 shell 脚本,我用它来循环遍历目录,并调用另一个 shell 脚本。我在本地机器(运行 bash 3.2 的 OSX)上编写它,并在运行 bash 4.2 的远程服务器上使用它。

On the server, when I type which bash, I get /bin/bash, so I added the line on top. I still get this error, pointing to the line that begins arrIN=...

在服务器上,当我输入时which bash,我得到/bin/bash,所以我在顶部添加了一行。我仍然收到此错误,指向开始的行arrIN=...

8: run_all_verification.sh: Syntax error: "(" unexpected (expecting "done")

The shell script:

外壳脚本:

#!/usr/bin/bash
#base name for all experiments
BASE_EXP_ID=;

for i in ${BASE_EXP_ID}*
do
        #split file name by "__"
        arrIN=(${i//__/ });
        EXP_ID=${arrIN[0]}
        NUM_FEATURES=${arrIN[1]}
        echo "${EXP_ID} ${NUM_FEATURES}"

        sh run_verification.sh ${EXP_ID} ${NUM_FEATURES}

done

回答by that other guy

Your error message is from dash, probably because you ran sh filename.

您的错误消息来自dash,可能是因为您运行了sh filename

To run a script with bash, use bash filename(or ./filename).

要使用 运行脚本bash,请使用bash filename(或./filename)。