Documentation of 'org.clapper.util.text.UnixShellVariableSubstituter' Java class
UnixShellVariableSubstituter
org.clapper.util.text

Class UnixShellVariableSubstituter

  • All Implemented Interfaces:
    VariableNameChecker, VariableSubstituter


    public class UnixShellVariableSubstituter
    extends AbstractVariableSubstituter

    The UnixShellVariableSubstituter class implements the VariableSubstituter interface and provides an inline variable substitution capability using a simplified Unix Bourne (or GNU bash) shell variable syntax. This syntax recognizes the "$var", "${var}" and "${var?default} sequences as variable references. For example, given the string (variables in bold):

     file:$user.home/profiles/$PLATFORM/${cfg?config}.txt
     

    and the variable values:

     user.home=/home/bmc
     PLATFORM=freebsd
     

    a UnixShellVariableSubstituter will produce the result string (substitutions noted in bold):

     file:/home/bmc/profiles/freebsd/config.txt
     
    Notes and Caveats
    1. To include a literal "$" character in a string, precede it with a backslash.
    2. If a variable doesn't have a value, its reference is replaced by an empty string, unless it is of the form ${var?default}. For instance, if variable foo does not have a value, the string $foo will substitute "", ${foo} will substitute "", and ${foo?foo value} will substitute "foo value".
    3. As with all VariableSubstituter classes, an instance of the UnixShellVariableSubstituter class enforces its own variable syntax (Unix Bourne shell-style, in this case), but defers actual variable value resolution to a separate VariableDereferencer object. One consequence of that approach is that variable names may be case-sensitive or case-insensitive, depending on how the supplied VariableDereferencer object interprets variable names.

    It's also possible to configure a UnixShellVariableSubstituter to throw a UndefinedVariableException, rather than substituting a blank, if a variable is undefined and a default value is not specified. See the AbstractVariableSubstituter.setAbortOnUndefinedVariable(boolean) method.

    See Also:
    WindowsCmdVariableSubstituter, VariableDereferencer, VariableSubstituter, String

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.