Search code examples
bashunixsolaris

bash - meaning of "( doSomething ) || :"


I stumbled upon this line of code:

( cd ${TRASH_DIR} && rmdir 20* 2> /dev/null ) || :

The first expression is clear to me, but what is the meaning of the "else-Part": just ":"? Mostly I see "|| exit 1" in these cases, which is clear to me as well.

PS: Unfortunately I seem not to be able to google this character-combination without having a hint what it means...


Solution

  • Definition of meaning of the ":" shell character can be found here. This is the snippet you need to locate; it is hard to be searched for on this lengthy page:

    : null command [colon]. This is the shell equivalent of a "NOP" (no op, a do-nothing operation). It may be considered a synonym for the shell builtin true. The ":" command is itself a Bash builtin, and its exit status is true (0).

    In the code line you consider in your question, it is only used to ensure final exit code of 0 of the expression, independent from the conditions checked there.