如果PS Aux | grep'name ofService'' | grep -v grep>/dev/null
我是《外壳》脚本的初学者,我对写作后的事情感到困惑。 /dev/null如果
ps aux | grep "nameOfService" | grep -v grep >/dev/null ?
I am beginner in shell scripting and i am confused about the thing that after writing > /dev/null what will be the value of if
ps aux | grep "nameOfService" | grep -v grep >/dev/null ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,管道的返回值是最后一个命令的返回值(在这种情况下,第二个
grep
命令)。请注意,PipeFail
Shell选项会更改此行为。重定向
grep
的输出不会更改返回值。您可能正在寻找类似的内容:
您应该使用
-w
匹配整个单词。我将使用awk -v'n = nameOfService''$ 4 == n'
而不是grep
,但是解析ps ps
输出不可靠反正。例如,PS
通常将过程名称截断为16个字符。By default, the return value of a pipeline is the return value of the last command (in this case, the second
grep
command). Note that thepipefail
shell option changes this behaviour.Redirecting the output of
grep
doesn't change the return value.You are probably looking for something like:
You should use
-w
to match the whole word. I would useawk -v 'n=nameOfService' '$4==n'
instead ofgrep
, however parsingps
output like this not reliable anyway. For example,ps
usually truncates process names to 16 characters.