Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm writing a shell function that will be called from many different places and I want to ignore all errors occurring inside the function disabling the (possibly enabled) set -e shell option, executing set +e.

The problem is that I don't know if that option was set or not, so I don't know if it's really needed to disable it, and more important, if I need to set it again at the end.

So, how do I know if it is set or not? Is there any way to ignore errors of all commands inside a shell function ignoring the -e shell option if is set?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Look at the value of $-, if it contains an 'e', then the '-e' option is set. This variable contains a list of all set options. This is described in the bash man page.

share|improve this answer
    
Fantastic, thank you very much (I cannot accept this answer yet, I must wait 5 minutes) –  Carlos Campderrós Sep 10 '12 at 14:26
2  
You can check with something like [[ $- =~ e ]]. –  Ansgar Wiechers Sep 10 '12 at 14:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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