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-`

closed as off topic by mikewhatever, ish, jokerdino, James Henstridge, jrg 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)

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