linux 中 grep命令 $?返回值 0、1、2的意义

 

0:找到匹配模式

1:未找到匹配模式

2:指定的输入文件不对

001、

复制代码
[root@pc1 test1]# ls
a.txt
[root@pc1 test1]# cat a.txt            ## 测试文本
aa bb cc
11 aa 33
33 dd bb
[root@pc1 test1]# grep "aa" a.txt      ## 匹配aa
aa bb cc
11 aa 33
[root@pc1 test1]# echo $?              ## 匹配到,返回0
0
[root@pc1 test1]# grep "xx" a.txt      ## 未匹配到xx,返回1
[root@pc1 test1]# echo $?
1
[root@pc1 test1]# grep "aa" b.txt      ## 指定的文件不对,返回2
grep: b.txt: No such file or directory
[root@pc1 test1]# echo $?
2
[root@pc1 test1]# grep "xx" b.txt
grep: b.txt: No such file or directory
[root@pc1 test1]# echo $?
2
复制代码

 。

 

posted @   小鲨鱼2018  阅读(386)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
点击右上角即可分享
微信分享提示