加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 基于grep结果的echo

发布时间:2020-12-15 18:39:12 所属栏目:安全 来源:网络整理
导读:我需要一个显示’是’或’否’的衬垫,无论grep是否找到任何结果. 我玩过grep -c,但没有成功. 怎么样: uptime | grep user echo 'yes' || echo 'no'uptime | grep foo echo 'yes' || echo 'no' 然后你可以安静下来: uptime | grep --quiet user echo 'yes'
我需要一个显示’是’或’否’的衬垫,无论grep是否找到任何结果.

我玩过grep -c,但没有成功.

怎么样:
uptime | grep user && echo 'yes' || echo 'no'
uptime | grep foo && echo 'yes' || echo 'no'

然后你可以安静下来:

uptime | grep --quiet user && echo 'yes' || echo 'no'
uptime | grep --quiet foo && echo 'yes' || echo 'no'

从grep手册页:

EXIT STATUS

Normally,the exit status is 0 if selected lines are found and 1 otherwise. But the exit status is 2 if an error occurred,unless the -q or –quiet or –silent option is used and a selected line is found.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读