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.

Required fields*

3
  • It seems to me that oldstate=$(set +o) is a simpler (and POSIX) way to store all options. Commented Sep 20, 2016 at 22:48
  • @sorontar, good point though that doesn't work for shell implementations like pdksh/mksh (and other pdksh derivatives) or zsh where set +o only outputs the deviations from the default settings. That would work for bash/dash/yash but not be portable. Commented Sep 21, 2016 at 8:35
  • for older shells use the answer by user232326 (you need to to read and understand the entire answer, and the caveats, and the subtleties, and you have to use eval which can be a security risk) --> if you have the new shell feature local - then local - is one line of code and does all the saving and restoring for you... without caveats or eval. Commented Jan 9, 2024 at 14:45