Shell Scripting – Utility of the : Command

shellshell-script

In the answer to this question about comments in shell scripting, it is indicated that the : is a null command that explicitly does nothing (but is not to be used for comments).

What would be the utility of a command that does absolutely nothing?

Best Answer

I typically use true in loops; I think it's more clear:

while true; do
    ...
done

The one place I've found that : is really handy is in case statements, if you need to match something but don't want to actually do anything. For example:

case $answer in
    ([Yy]*) : ok ;;
    (*)     echo "stop."; exit 1 ;;
esac
Related Question