Command : - this is a zero utility :
This utility should only expand the arguments of the command. It is used when a command is required, as in the case of then if command, but nothing should be done by the command.
Also Built-in Bourne Shells :
Do nothing but expand the arguments and perform the redirect. The return status is zero.
The syntax ${foo:=bar} is a special parameter extension :
${parameter:=[word]}
Assign default values. If the parameter is not specified or null, the parameter extension (or an empty string if the word is omitted) is assigned to the parameter. In all cases, the final value of the parameter must be replaced. This way you can only assign variables, not positional parameters or special parameters.
Bash Reference Guide Record :
${parameter:=word}
If the parameter is not specified or null, the word extension is assigned to the parameter. Then the parameter value is replaced. Therefore, you cannot assign positional parameters and special parameters.
So, on the command line of your question:
: ${foo:=bar}; export foo
There are two teams:
The first of which extends the variable foo , and if it is empty or not set, assigns it the value bar .
The second one then exports the variable foo for sub-shells and other processes.
source share