default - How to guarantee grep returns at least one line -


i'd run script runs grep command , outputs result. expect grep return 1 line, want handle case there no matching line (for example if grepped file not exist). there way execute like

line = grep ... if line empty    print "\n" else    print line 

all need examine return code of grep.

grep returns 0 if line matched , 1 if no lines matched. returns value greater 1 if error occurred.

$ echo "hi" | grep hi hi $ echo $? 0 $ echo "hi" | grep hello $ echo $? 1 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -