bash assign default value
bash
Solution
Use a colon:
: ${A:=hello}
The colon is a null command that does nothing and ignores its arguments. It is built into bash so a new process is not created.
Problem
${parameter:=word} Assign Default Values. If parameter is unset or null, the expansion of word is assigned to parameter. The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way. I thought I could use this feature to write `${LONG_VARIABLE_NAME:=hello}` instead of the longer `LONG_VARIABLE_NAME=${LONG_VARIABLE_NAME:-hello}`, but now bash also tries to execute 'hello' and that gives a command not found. Any way to avoid that? Or will I have to stick to the latter? Can someone give an example where the assign default is actually useful?