autoconf: Assignments
1
1 11.9 Assignments
1 ================
1
1 When setting several variables in a row, be aware that the order of the
1 evaluation is undefined. For instance `foo=1 foo=2; echo $foo' gives
1 `1' with Solaris `/bin/sh', but `2' with Bash. You must use `;' to
1 enforce the order: `foo=1; foo=2; echo $foo'.
1
1 Don't rely on the following to find `subdir/program':
1
1 PATH=subdir$PATH_SEPARATOR$PATH program
1
1 as this does not work with Zsh 3.0.6. Use something like this instead:
1
1 (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
1
1 Don't rely on the exit status of an assignment: Ash 0.2 does not
1 change the status and propagates that of the last statement:
1
1 $ false || foo=bar; echo $?
1 1
1 $ false || foo=`:`; echo $?
1 0
1
1 and to make things even worse, QNX 4.25 just sets the exit status to 0
1 in any case:
1
1 $ foo=`exit 1`; echo $?
1 0
1
1 To assign default values, follow this algorithm:
1
1 1. If the default value is a literal and does not contain any closing
1 brace, use:
1
1 : "${var='my literal'}"
1
1 2. If the default value contains no closing brace, has to be
1 expanded, and the variable being initialized is not intended to be
1 IFS-split (i.e., it's not a list), then use:
1
1 : ${var="$default"}
1
1 3. If the default value contains no closing brace, has to be
1 expanded, and the variable being initialized is intended to be
1 IFS-split (i.e., it's a list), then use:
1
1 var=${var="$default"}
1
1 4. If the default value contains a closing brace, then use:
1
1 test "${var+set}" = set || var="has a '}'"
1
1 In most cases `var=${var="$default"}' is fine, but in case of doubt,
1 just use the last form. ⇒Shell Substitutions, items
1 `${VAR:-VALUE}' and `${VAR=VALUE}' for the rationale.
1