Quote:
|
Originally Posted by manthasirisha
1. why is there a /dev/null in his piece of code?
|
I did mention that if grep finds anything, it will output whatever it found. Together with that, the exit status will be set accordingly.
See this
Code:
[/tmp]$ cat xyz
maroon
pink
yellow
[/tmp]$ grep pink xyz
pink
[/tmp]$ echo $?
0
[/tmp]$ grep pink xyz 1> /dev/null
[/tmp]$ echo $?
0
[/tmp]$ grep pink xyz.file 1> /dev/null
grep: xyz.file: No such file or directory
[/tmp]$ echo $?
2
[/tmp]$ grep pink xyz.file 1> /dev/null 2> /dev/null
[/tmp]$ echo $?
2
[/tmp]$ grep pink xyz 1> /dev/null 2> /dev/null
[/tmp]$ echo $?
0
[/tmp]$
That should explain the role of /dev/null. If not, read it from up the
wiki site.
Quote:
|
Originally Posted by manthasirisha
2. How are achieving the same without a grep in your solution?
|
The non-grep solution makes use of a shell-builtin.
See this thread -
String extraction from user input - sh
vino