GNU Rush |
|
Restricted User Shell |
Sergey Poznyakoff |
set
statementThe set
statement modifies the value of a positional, request,
or user-defined variable.
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.
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.
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:
Apply the replacement to all matches to the regexp, not just the first.
Use case-insensitive matching
regexp is an extended regular expression (see Extended regular expressions in GNU sed).
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/
This document was generated on January 2, 2022 using makeinfo.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.