Never seen this used before in BASH:
pidfile=${PIDFILE-/var/run/service.pid}
The part I've never seen/used before is the ${PIDFILE-
part.
Never seen this used before in BASH:
pidfile=${PIDFILE-/var/run/service.pid}
The part I've never seen/used before is the ${PIDFILE-
part.
It means use
$PIDFILE
if$PIDFILE
is defined, or/var/run/service.pid
if$PIDFILE
is undefined.Starting with a new shell:
Now define PIDFILE:
It is from the old days of Bourne Shell sh man page.
The other form you might have already seen is
${parameter:-word}
. It is similar, but behaves differently ifparameter
is set to the empty string.To demonstrate:
Note how
${NULLVAR-default}
expands to the empty string, becauseNULLVAR
is defined.For a full explanation, run "man bash" and search for Parameter Expansion by typing "/Parameter Expansion".
The ${parameter-word} bit is hidden away in this explanation:
Thanks to Dennis for the correction about set versus null.
Mikel:
shouldn't it be
pidfile=${PIDFILE:-/var/run/service.pid}
the way you are explaining?