Let's break this down into pieces.
This code runs the command :
with some arguments. The command :
does nothing and ignores its arguments. Therefore the whole command line does nothing, except whatever side effects happen in the arguments.
The syntax ${parameter_name:=value}
exists in all non-antique Bourne-style shells, including ash, bash, ksh and zsh. It sets the parameter to a default if necessary. It is equivalent to
if [ -z "$parameter_name" ]; then parameter_name=value; fi
… ${parameter_name}
In other words, if parameter_name
is not set or is set to an empty value, then set it to the indicated value; and then run the command, using the new parameter value. There is a variant, ${parameter_name=value}
, which leaves the parameter empty if it was empty, only using the indicated value if the parameter was unset.
You'll find this syntax documented under “parameter expansion” in the POSIX spec, and the dash, bash, ksh and zsh manuals.
There are variations on this syntax, in particular ${parameter_name:-value}
which let you use a default value for this expansion only, without assigning to the parameter.
In summary, : ${parameter_name:=value}
is a concise way of writing
if [ -z "$parameter_name" ]; then parameter_name=value; fi
Just for completeness, you don't need all those (") nor the final $(echo ...)
.
Here's the simplified version of your assignments that produce the same
effect:
STARTIME=$(date +"%T")
ENDTIME="$STARTIME today + 10 seconds"
CALL="date -d '$ENDTIME' +'%H:%M:%S'"
Note how you don't need to quote when doing var=$(...) but you do usually
with var="many words":
a=$(echo 'a b'); echo "$a" # result: a b
Inside (") a (') has no special significance, and vice-versa, eg:
a="that's nice"; echo "$a" # result: that's nice
a='that "is nice'; echo "$a" # result: that "is nice
Best Answer
After the variable is expanded, word-splitting occurs and it gets split into empty word(s). Splitting is done using each character of the
IFS
variable as delimiter and since$IFS
only expands to characters in theIFS
it gets split into empty word(s).So, for example:
And if you double quote, you are telling bash to treat everything inside the quotes as one word: