我有一个在 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] 删除。
我来说两句