例如,我有一个文件
$ cat test.file
a
b
c
如果我
grep
有输出,我得到echo $?
到0
$ grep a test.file
a
$ echo $?
0
但是如果我
grep
没有输出,我得到echo $?
到1
$ grep x test.file
$ echo $?
1
因为我从
$?
到 1
,所以我使用此命令的管道失败了。
我应该怎么做才能获得与
0
一致的结果,因为 grep 没有输出对我来说很好
只需添加
or true
和结尾
grep not_found myinput.file || : # same as /usr/bin/true