Ubuntu – The point of the bash Null-operator “:”, colon

bashscriptssyntax

What is the point of the "null" operator in a BASH script? I understand that it is used as a placeholder following an if command when you have nothing to say, but need a command to allow the program to run properly. But what is the overall use for it? When would you use it? When does it make sense to use it?

Best Answer

It's sometimes useful to allow parameter expansions side-effects to occur.

For example, setting a default value

read -p "Enter your name: " name
: ${name:=John Doe}  # if the user entered an empty string
echo "$name"