In a bash shell I tried the following 2 commands producing different effects:
$ a=`echo UPDATED` echo ${a:-DEFAULT}
DEFAULT
$ a=`echo UPDATED`; echo ${a:-DEFAULT}
UPDATED
Isn't possible to achive the result in one command (first case) ? And if not, why?
Some quotes from the man:
A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator.
Expansion is performed on the command line after it has been split into words.
For clarity, the real wold case involves providing a binary to be executed by an event handler. The binary path is got from a configuration file, falling back to default if not defined in the configuration file.
Something closer to real case is this snippet, that is called by event handler:
a=`getConfigVariable "myExec"` ${a:-/opt/bin/default}
Where getConfigVariable "myExec" returns the configuration variable "myExec", or an empty string if it is not defined. For example:
$ getConfigVariable "myExec"
/opt/bin/updated
a='UPDATED'in both commands ?