[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


...find exit status of the "grep" command in the...

<< Back to: Unix - Frequently Asked Questions (1/7) [Frequent posting]

Question by ashish
Submitted on 5/12/2004
Related FAQ: Unix - Frequently Asked Questions (1/7) [Frequent posting]
Rating: Not yet rated Rate this question: Vote
how can i find exit status of the "grep" command in the following statement:->
echo `grep $username myfile | cut -f 3`


Answer by ponkan
Submitted on 3/2/2006
Rating: Not yet rated Rate this answer: Vote
since getting the exit status via echo $? gives the status of the last command run, ensure that grep is the last command run by redirecting output to a file, check exit status, then run the cut command on the file.

grep $username myfile > foo
echo $?
cut -f 3 foo

alternatively, since the cut command might produce several pages of output, store the exit status in another variable.

grep $username myfile > foo
EXIT=$?
cut -f 3 foo
echo grep's exit status was $EXIT

 

Answer by arunkannan
Submitted on 10/18/2006
Rating: Not yet rated Rate this answer: Vote
I think, it is impossible to find status for grep command in the above mentioned command sequence statement....

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: Unix - Frequently Asked Questions (1/7) [Frequent posting]


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.