Return value of grep and ls
来源:互联网 发布:微信公众营销软件 编辑:程序博客网 时间:2024/05/11 03:09
I make some testing below:
---------------------------------------------------------------------------------------------
$ ls
aa.txt ab.txt bb.txt
$ ls | grep -v 'aa.txt' | grep -v 'bb.txt'
ab.txt
$ echo $?
0
$ ls | grep -v 'aa.txt' | grep -v 'bb.txt' |grep -v 'ab.txt'
$ echo $?
1
$ ls | grep -E -v '(aa.txt|bb.txt|ab.txt)'
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
$ ls | /usr/xpg4/bin/grep -E -v '(aa.txt|bb.txt|ab.txt)'
$ echo $?
1
$ ls abc.txt
abc.txt: No such file or directory
$ echo $?
2
--------------------------------------------------------------
From the testing above, we can find that if ls can’t find certain file,the return value will be 2,and display some error message, that is this command failed. If we use ls without parameters and there are no files in the current diretory, ls will return 0, that is this command successfully be executed.
But grep works in another way. According to the pattern grep will filter some lines. if no line get thought, the return value is 1, if some lines get thought, the return value is 0. so the return value of grep is 1 not mean grep fail, but no line get thought.
- Return value of grep and ls
- ls, find and grep's parameters and xargs
- About the return value of SetTimer function
- return value of operator overloading in C++
- Exclude all lines match a pattern using ls and grep
- ls -F | grep /$是什么意思
- The return value of "mktime" in different time zone
- 解决Deprecated: Assigning the return value of new by reference
- ReactNative : ignoring return value of function declared with warn_unused_result attribute
- Warning 534: Ignoring return value of function 'printf
- ReactNative : ignoring return value of function declared with warn_unused_result attribute
- No converter found for return value of type解决方法
- Differenct between return by value and by reference
- The Definition of Key Value Coding and Key Value Observing
- linux shell: rm 、ls、grep
- linux命令---ls、grep、cat
- linux ls find rename grep
- the meaning of awk grep rc and perl
- ksh学习
- cat and line
- 读《J2EE核心模式》(DAO模式)
- 利用VC++实现串口收发短消息
- Exclude all lines match a pattern using ls and grep
- Return value of grep and ls
- FTP调用的方法
- The difference between (()) and ().
- linux字体配置文件fonts.dir分析
- 定期获取远程FTP站点之内容
- named pipe
- BizTalk Server 2006 系统需求
- IF语句
- EJB3.0介绍