bash脚本没有回声做结束 [英] Bash script ends without doing echo

查看:146
本文介绍了bash脚本没有回声做结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从命令行运行一个脚本,如果4个变量设置运行一堆的JMeter测试。

I am running a script from command line that runs a bunch of Jmeter tests if 4 variables are set.

该脚本工作,但我已经加入部分,这样如果服务器是未知脚本将结束。

The script works but I have added parts so the script will end if the server is unknown.

if [ echo "$2" != | grep -iq "^hibagon" ] || [ echo "$2" != | grep -iq "^kameosa" ] ;then
echo "Unkown server stopping tests" 
  else
echo "Continueing to tests"

当脚本的这一部分运行时,它会结束脚本如果hibagon或kameosa找不到

(不区分大小写)。

when this section of the script runs it will end the script if hibagon or kameosa is not found (not case sensitive).

我想通过命令行来呼应未知的服务器停止测试,然后结束,但目前它只是无回声结束

I want the command line to echo Unknown server stopping tests then end but at the moment it just ends with no echo

推荐答案

这是一个奇怪的语法。试试这个:

That's a strange syntax. Try this:

if echo "$2" | grep -iq "^hibagon\|^kameosa";
then 
    echo "Continuing to tests"
else
    echo "Unkown server, stopping tests" 
fi

或者,如果你正在使用bash:

Or if you're using bash:

if [[ "$2" =~ ^hibagon ]] || [[ "$2" =~ ^kameosa ]]
then
    echo "Continuing to tests"
else
    echo "Unkown server, stopping tests" 
fi

这篇关于bash脚本没有回声做结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆