The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 01-11-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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

Last edited by vino; 01-11-2006 at 08:46 AM..