Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fetching specific value from a text file using sed into a variable.
If the file does not exist, an error will be printed:

sed: can't read filepath: No such file or directory

How can I catch this error and display my own message and do my logic?

export RESULT=`sed '' ${FILE_PATH} | grep ${VAR_NAME}  | cut -d "=" -f2-`
share|improve this question

closed as off topic by mikewhatever, izx, jokerdino, James Henstridge, James Jul 3 '12 at 11:43

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

sed returns non-zero exit code when it fails. So you need to test $? after sed (but before the pipes, else their possibly zero exit codes may "overwrite" sed's)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.