Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • That works great - except that $? is changed as well. But thats how the system works I guess... Commented Jun 6, 2013 at 10:57
  • @Den Yes, $? always holds the result of the last command. You are supposed to save it to some other variable if you want to keep the result of a specific command for later. Commented Jun 6, 2013 at 11:51
  • @Den Note that if ...; then ... can be rewritten as ...; if $? = 0; then ... for elided parts in the same order. That may be more in line with what you want to do, because then you have a good place in which to save the value of $? to somewhere else. Commented Jun 6, 2013 at 11:53
  • Ah, right, silly me. Commented Jun 6, 2013 at 12:00
  • Note that this "reversal" of the exit code involves some information loss: Instead of a value from 0 through 255 you'll get either 0 or 1. Commented Jun 6, 2013 at 12:16