2

See: What is the Bash equivalent of Python's pass statement

What is this ":" colon usage called? For example:

if [[ -n $STRING ]]; then
    #printf "[INFO]:STRING: if -n string: STRING:$STRING \n"
    : 
else
    printf "[INFO]:Nothing in the the string\n"
fi
Community
  • 1
  • 1
jmunsch
  • 22,771
  • 11
  • 93
  • 114

1 Answers1

4

To what that is, run help : in the shell. It gives:

$ help :
:: :
    Null command.

    No effect; the command does nothing.

    Exit Status:
    Always succeeds.

Very useful in one-liner infinite loops, for example:

while :; do date; sleep 1; done

Again, you could write the same thing with true instead of :, but this is shorter.

Interestingly:

$ help true
true: true
    Return a successful result.

    Exit Status:
    Always succeeds.

According to this, the difference is that : is "Null command", while true is "Returns a successful result". Another difference is that true is usually a real binary:

$ which true
/usr/bin/true

On the other hand, which : gives nothing. (Which makes sense, being a "null command".)

Anyway, @Andy is right, this is duplicate of this other post, which explains it much better.

Community
  • 1
  • 1
janos
  • 120,954
  • 29
  • 226
  • 236