2

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...

chicks
  • 2,393
  • 3
  • 24
  • 40
evilive
  • 916
  • 1
  • 7
  • 24

1 Answers1

3

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.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Artur Opalinski
  • 1,052
  • 7
  • 12
  • Thank You: Found It now with symbolhound here on stackoverflow as well: In this case it was in the last line of the script for exiting successfull even if there were suppressed errors in the first expression – evilive May 27 '16 at 07:52
  • 1
    @evilive In that case you could just put `exit 0` at the end, which is obviously far clearer as this question wouldn't exist if the last person did that! – 123 May 27 '16 at 07:54
  • 1
    @123 Thank you! Just did that even before reading this ;) – evilive May 27 '16 at 07:55