Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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, 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.

1 Answer 1

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.