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.

12
  • 5
    Well, without set -e there's no need for || true at all, I thought it important to provide the context. If you notice odd things on POWER, I strongly encourage you to file bugs (reportbug)! Commented Nov 24, 2016 at 12:34
  • 22
    @MichaelFelt, actually set -e is not only "Debian convention", but a good programming pattern one should always use. See. e.g. davidpashley.com/articles/writing-robust-shell-scripts Commented Nov 24, 2016 at 13:57
  • 2
    per the question here - why use || true set -e is the likely context and likely the most common. I bow to this answer! Literally though, it is useful anytime exit status is deemed irrelevant AND (as you article link adds) I am not using exit status as part of my script control. I see utility (in set -e) but would not go so far as the article does and say "Every script you write should include set -e at the top". It is a style of programming. "ALWAYS | Every" includes it own set of traps - aka - absolutes re: wild-card solutions will ALWAYS backfire eventually aka - no free rides. Commented Nov 24, 2016 at 14:58
  • 2
    @StephenKitt Sure thing. There is a very thorough page documenting different shells' set -e behaviors by Sven Mascheck, though this page also documents a lot of historical/ancient shells irrelevant today. There's also these two pages with a narrower modern focus (search for "set -e"): "lintsh" page, autoconf's portable shell documentation -> Limitation of Builtins subpage Commented Nov 26, 2016 at 22:50
  • 2
    @400theCat I don't think so. The idea here is that by default (with set -e), non-zero exit codes cause the script to stop (remember, we're in the context of package maintainer scripts, so it's important to stop early when errors are detected). Then if you add a command without thinking too much about it, you're "protected"; you can special-case commands whose exit code is ignored using || true, and that jumps out at you when you read the script. With your approach, we'd end up with || exit everywhere. (The OP was exaggerating, you don't see || true everywhere in these scripts.) Commented Dec 23, 2016 at 10:21