Bash 脚本没有回显就结束了
Bash script ends without doing echo
我是运行来自命令行的脚本,如果设置了 4 个变量,它会运行一堆 Jmeter 测试。
脚本有效,但我添加了一些部分,因此如果服务器未知,脚本将结束。
if [ echo "" != | grep -iq "^hibagon" ] || [ echo "" != | grep -iq "^kameosa" ] ;then
echo "Unkown server stopping tests"
else
echo "Continueing to tests"
当这部分脚本运行时,如果未找到 hibagon 或 kameosa(不区分大小写),它将结束脚本。
我希望命令行回显未知服务器停止测试然后结束,但目前它只是结束而没有回显
首先测试 [ echo "" != | grep -iq "^hibagon" ]
是错误的,然后你可以只使用一个(扩展)grep 与否定标志 -v
将两个词放在一个正则表达式 ^(hibagon|kameosa)
中。 fi
也不见了。但我想这只是一个错字。
if echo "" | egrep -ivq "^(hibagon|kameosa)"; then
echo "Unknown server stopping tests"
else
echo "Continuing to tests"
fi
如果喜欢,甚至:
if egrep -ivq "^(hibagon|kameosa)" <<< ""; then
这是一个奇怪的语法。试试这个:
if echo "" | grep -iq "^hibagon\|^kameosa";
then
echo "Continuing to tests"
else
echo "Unkown server, stopping tests"
fi
或者如果您使用的是 bash:
if [[ "" =~ ^hibagon ]] || [[ "" =~ ^kameosa ]]
then
echo "Continuing to tests"
else
echo "Unkown server, stopping tests"
fi
我是运行来自命令行的脚本,如果设置了 4 个变量,它会运行一堆 Jmeter 测试。
脚本有效,但我添加了一些部分,因此如果服务器未知,脚本将结束。
if [ echo "" != | grep -iq "^hibagon" ] || [ echo "" != | grep -iq "^kameosa" ] ;then
echo "Unkown server stopping tests"
else
echo "Continueing to tests"
当这部分脚本运行时,如果未找到 hibagon 或 kameosa(不区分大小写),它将结束脚本。
我希望命令行回显未知服务器停止测试然后结束,但目前它只是结束而没有回显
首先测试 [ echo "" != | grep -iq "^hibagon" ]
是错误的,然后你可以只使用一个(扩展)grep 与否定标志 -v
将两个词放在一个正则表达式 ^(hibagon|kameosa)
中。 fi
也不见了。但我想这只是一个错字。
if echo "" | egrep -ivq "^(hibagon|kameosa)"; then
echo "Unknown server stopping tests"
else
echo "Continuing to tests"
fi
如果喜欢,甚至:
if egrep -ivq "^(hibagon|kameosa)" <<< ""; then
这是一个奇怪的语法。试试这个:
if echo "" | grep -iq "^hibagon\|^kameosa";
then
echo "Continuing to tests"
else
echo "Unkown server, stopping tests"
fi
或者如果您使用的是 bash:
if [[ "" =~ ^hibagon ]] || [[ "" =~ ^kameosa ]]
then
echo "Continuing to tests"
else
echo "Unkown server, stopping tests"
fi