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
。
分类:
linux shell
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章