Next: , Previous: , Up: Component Statement   [Contents][Index]


3.3.5 Early Environment Expansion

By default any references to environment variables encountered in the command statement are not expanded. If you need to expand them, there are two flags (see flags) at your disposal: ‘shell’ and ‘expandenv’.

The ‘shell’ flag instructs pies to pass the command line specified by the the command statement as the argument to the ‘/bin/sh -c’ command (or another shell, if specified by the ‘program’ statement). This naturally causes all references to the environment variables to be expanded, as in shell. The overhead is that two processes are run instead of the one: first the shell and second the command itself, being run as its child. This overhead can be eliminated by using the exec statement before the command, to instruct the shell to replace itself with the command without creating a new process.

Use this flag if the command you use in the component definition is a shell built-in, a pipe or another complex shell statement.

Another way to expand environment variables in the command line is by specifying the ‘expandenv’ flag. This flag instructs pies to expand any variable references the same way that the Bourne shell would expand them, but without actually invoking the shell.

A variable reference has the form ‘$variable’ or ‘${variable}’, where variable is the variable name. The two forms are entirely equivalent. The form with curly braces is normally used if the variable name is immediately followed by an alphanumeric symbol, which will otherwise be considered part of it. This form also allows for specifying the action to take if the variable is undefined or expands to an empty value:

${variable:-word}

Use Default Values. If variable is unset or null, the expansion of word is substituted. Otherwise, the value of variable is substituted.

${variable:=word}

Assign Default Values. If variable is unset or null, the expansion of word is assigned to variable. The value of variable is then substituted.

${variable:?word}

Display Error if Null or Unset. If variable is null or unset, the expansion of word (or a message to that effect if word is not present) is output to the current logging channel. Otherwise, the value of variable is substituted.

${variable:+word}

Use Alternate Value. If variable is null or unset, nothing is substituted, otherwise the expansion of word is substituted.

When the two flags are used together, the preference is given to ‘shell’, and a warning message to that effect is issued.

Also, please note, that whichever option you chose the environment variables available for expansion are those inherited by the parent shell and modified by the env statement (see Environment).


Next: , Previous: , Up: Component Statement   [Contents][Index]