[英]Bash: echo showing blank value
I have two variables as follows 我有两个变量如下
SampleOutput=`some command giving output`
Status=`echo "$SampleOutput" | grep -qs "Active"`
echo $SampleOutput
echo $Status
Here $SampleOutput
has value as AgentEnable=Active bla bla bla
这里
$SampleOutput
值为AgentEnable=Active bla bla bla
However, $Status
is coming as blank
I am not sure why $Status
is coming as blank when it should have value AgentEnable=Active
但是,
$Status
将AgentEnable=Active
blank
我不确定为什么$Status
在它应该具有值时显示为空白AgentEnable=Active
When using grep -q
you don't get any output from grep
. 使用
grep -q
你不会从grep
获得任何输出。 Only return status is available that you can get using: 只有您可以使用的退货状态:
grep -qs "Enable" <<< "$SampleOutput"
Status=$?
As per man grep
: 按照
man grep
:
-q, --quiet, --silent
Quiet mode: suppress normal output.-q, --quiet, --silent
quiet-q, --quiet, --silent
安静模式:抑制正常输出。 grep will only search a file until a match has been found, making searches potentially less expensive.grep只会搜索文件,直到找到匹配项,从而使搜索成本更低。
Note that if you are not using SampleOutput
anywhere else then you can directly use: 请注意,如果您未在其他任何地方使用
SampleOutput
则可以直接使用:
some command | grep -qs "Enable"
Status=$?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.