当我将服务传输到grep时 - status-all命令时,为什么在输出中显示额外的线?
例如,
sudo service --status-all | grep -oE 'php[0-9]+.[0-9]+'
生成以下输出。
[ ? ] hwclock.sh
[ ? ] networking
php7.0
php7.3
我的目标是提取另一个软件包的版本,并将其放入配置脚本中,以便如果该软件包得到升级或降级,则该脚本不会破坏。如果我对正则表达式和管道操作员的理解是正确的,则前两行甚至不应显示在输出中。
谁能向我解释为什么会发生这种情况?
For example,
sudo service --status-all | grep -oE 'php[0-9]+.[0-9]+'
generates the following output.
[ ? ] hwclock.sh
[ ? ] networking
php7.0
php7.3
My goal is to extract the version of another software package and put it into a configuration script so that the script won't break if that package gets upgraded or downgraded. If my understanding of regular expressions and the piping operator is correct, the first two lines shouldn't even show up in the output.
Can anyone explain to me why this is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将输出重定向到STDERR消除了不需要的线路。我还将输出输送到 tail -1 仅获取最后一行 - 具有最新版本的一行。
Redirecting the output to stderr eliminated the unwanted lines. I also piped the output to tail -1 to get the last line only--the one with the latest version.