Bash 语法问题,'语法错误:意外的“do”(期望“fi”)'

卡尔

我有一个在 Windows 和 Mac/Linux 机器上使用的 sh 脚本,并且似乎正常工作没有问题。

#!/bin/bash
if [ -z "$jmxname" ]
then
cd ./tests/Performance/JMX/ || exit

echo "-- JMX LIST --"

# set the prompt used by select, replacing "#?"
PS3="Use number to select a file or 'stop' to cancel: "

# allow the user to choose a file
select jmxname in *.jmx
do
    # leave the loop if the user says 'stop'
    if [[ "$REPLY" == stop ]]; then break; fi

    # complain if no file was selected, and loop to ask again
    if [[ "$jmxname" == "" ]]
    then
        echo "'$REPLY' is not a valid number"
        continue
    fi

    # now we can use the selected file, trying to get it to run the shell script
    rm -rf ../../Performance/results/* && cd ../jmeter/bin/ && java -jar ApacheJMeter.jar -Jjmeter.save.saveservice.output_format=csv -n -t ../../JMX/"$jmxname" -l ../../results/"$jmxname"-reslut.jtl -e -o ../../results/HTML
    # it'll ask for another unless we leave the loop
    break
done
else
    cd ./tests/Performance/JMX/ && rm -rf ../../Performance/results/* && cd ../jmeter/bin/ && java -jar ApacheJMeter.jar -Jjmeter.save.saveservice.output_format=csv -n -t ../../JMX/"$jmxname" -l ../../results/"$jmxname"-reslut.jtl -e -o ../../results/HTML
fi

我现在正在尝试使用 Docker 容器做一些事情,并使用了 node:alpine 图像,因为我的项目的其余部分是基于 NodeJS 的,但由于某种原因,脚本不会在 Docker 容器中运行,给出以下内容 -

line 12: syntax error: unexpected "do" (expecting "fi")

我该如何解决?该脚本似乎适用于迄今为止运行过的每个系统,并且没有出现任何问题。

破折号

错误消息表明脚本是作为“/bin/sh”而不是/bin/bash 执行的。您可以看到带有“/bin/sh -n script.sh”的消息

检查脚本是如何调用的。在不同的系统上,/bin/sh 被符号链接到 bash 或其他功能较少的 shell。

特别是,问题出select在 bash 中语句上,但不是 POSIX 标准的一部分。

另一种选择是默认情况下将 docker 上的 bash 设置为符合 POSIX

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

语法错误:“(”意外(期望的单词)---在我的bash脚本中

bash脚本语法错误:单词意外(期望“做”)

Bash-意外令牌'fi'附近的语法错误

Bash 语法错误:fi 上的文件意外结束

bash脚本意外令牌'fi'附近的语法错误

Bash:语法错误:“(”意外

bash:意外令牌“ do”附近的语法错误

获取语法错误:shell 脚本中的“fi”意外(期望“then”)

令牌`fi'附近的bash语法错误

语法错误:“(”意外(期望“ then”)

bash:意外令牌'<'附近的语法错误

bash:意外令牌'('附近的语法错误

bash:意外令牌';'附近的语法错误

bash:意外令牌附近的语法错误

bash:意外令牌'}'附近的语法错误

-bash:意外令牌';'附近的语法错误

Ubuntu bash函数..语法错误:“(”或“}”意外

bash:语法错误:文件意外结束

Bash变量语法问题

语法错误:bash脚本中出现“ fi”意外(预期为“ then”)

Bash 脚本:嵌套语句中的“语法错误:“fi”意外”

我的bash脚本中出现“意外令牌'fi'附近的语法错误”

解析错误:语法错误,意外的'}',期望','或';' 在 /

Go golang,语法错误:意外++,期望:

MySQL:语法错误,意外的'@',期望的是':'

语法错误,意外的'\ n',期望=>(SyntaxError)

语法错误:单词意外(期望“)”)?

为什么我在 bash 脚本中收到“第 10 行:意外标记‘fi’附近的语法错误”错误?

bash shell脚本错误,带有:意外令牌'$'do \ r'附近的语法错误