【发布时间】:2020-02-15 09:17:45
【问题描述】:
我有一个在 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")
我该如何解决这个问题?到目前为止,该脚本似乎适用于它所运行的每个系统,并且没有引发任何问题。
【问题讨论】:
-
如何启动脚本?
-
通过 npm 命令“sh node_modules/ukri-test-framework/scripts/runPerformance.sh”
-
在 shell 脚本中使用
while或for循环做和做有意义 -
我认为这与 POSIX sh 有关,因为它是一种 bash 语法
-
它似乎很奇怪,它在我迄今为止使用的所有 windows/mac/linux 机器上都有效,但现在在 docker 容器中出现问题......
标签: node.js bash shell docker sh