GNU Rush – a restricted user shell (split by node):   Section:   Chapter:FastBack: Configuration File   Up: Modifying variables   FastForward: Default Configuration   Contents: Table of ContentsIndex: Concept Index

4.4.3.1 The set statement

The set statement modifies the value of a positional, request, or user-defined variable.

rule: set name = value
rule: set [n] = value

Sets the variable name to value. Prior to use, value undergoes backreference interpretation (see backreference) and variable expansion (see Variable expansion).

The second form assigns to the positional variable ‘$n’. It is discussed in more detail in Transformations.

rule: set name = value ~ s-expr
rule: set [n] = value ~ s-expr

Applies the sed search-and-replace expression s-expr to value and assigns the result to the variable name or argument n. Both value and s-expr are subject to variable expansion and backreference interpretation.

rule: set name =~ s-expr
rule: set [n] =~ s-expr

Applies the sed-like search-and-replace expression s-expr to the current value of the variable name and stores the resulting string as its new value. Prior to use, s-expr undergoes backreference interpretation (see backreference) and variable expansion (see Variable expansion). This is a shortcut for

set name = ${name:-""} ~ s-expr

Second form modifies the value of the positional variable ‘$n’. This statement is a shortcut for

set [n] = ${n:-""} ~ s-expr

See Transformations, for a detailed discussion.

The transformation expression, s-expr, is sed-like replace expression of the form:

s/regexp/replace/[flags]

where regexp is a regular expression, replace is a replacement for each part of the input that matches regexp and flags are optional flags that control the substitution. Both regexp and replace are described in The ‘s’ Command in GNU sed.

As in sed, you can give several replace expressions, separated by semicolons.

Supported flags are:

g

Apply the replacement to all matches to the regexp, not just the first.

i

Use case-insensitive matching

x

regexp is an extended regular expression (see Extended regular expressions in GNU sed).

number

Only replace the numberth match of the regexp.

Note: the POSIX standard does not specify what should happen when you mix the ‘g’ and number modifiers. Rush follows the GNU sed implementation in this regard, so the interaction is defined to be: ignore matches before the numberth, and then match and replace all matches from the numberth on.

Normally, the s-expr is a quoted string, and as such it is subject to backslash interpretation. It is therefore important to properly escape backslashes, especially in replace part. Consider this example:

set bindir = $program ~ "s/(.*)\\//\\1/"

The intention is to extract the directory part of the executable program name and store it in the variable ‘bindir’. Notice, that each backslash is escaped, so that the actual string that is compiled into a regular expression is

s/(.*)\//\1/

GNU Rush – a restricted user shell (split by node):   Section:   Chapter:FastBack: Configuration File   Up: Modifying variables   FastForward: Default Configuration   Contents: Table of ContentsIndex: Concept Index