The reason for this pattern is that maintainer scripts in Debian packages tend to start with set -e
, which causes the shell to exit as soon as any command (strictly speaking, pipeline, list or compound command) exits with a non-zero status. This ensures that errors don't accumulate: as soon as something goes wrong, the script aborts.
In cases where a command in the script is allowed to fail, adding || true
ensures that the resulting compound command always exits with status zero, so the script doesn't abort. For example, removing a directory shouldn't be a fatal error (preventing a package from being removed); so we'd use
rmdir ... || true
since rmdir
doesn't have an option to tell it to ignore errors.
||:
is another idiomatic way of writing this (:
being another entry in the builtin table pointing totrue
-- but guaranteed to be a builtin even back to Bourne; that said, for POSIX sh,true
is likewise guaranteed to be a builtin -- so it's more terseness than efficiency in even-remotely-modern times). – Charles Duffy Nov 26 '16 at 06:09