GNU Rush |
|
Restricted User Shell |
Sergey Poznyakoff |
The ‘setvar’ statement allows you to define or redefine variables. The syntax is:
When executing this statement, the pattern is first expanded using variable and backreference expansions (see patterns), then the resulting value is assigned to the variable name.
You can set both user-defined and built-in variables. The common use for the ‘setvar’ statement is to save the result of pattern matching for use in further rules, e.g.:
rule chdir command ^cd "(.+)" && (.*)$ setvar[workdir] %1 set %2 fall-through ... rule runcom command ^runcom chdir $workdir ...
Here, the rule ‘chdir’ saves the argument to the cd
command in the variable ‘workdir’, which will eventually be used
in the rule ‘runcom’ to actually change to that directory.
User-defined variables can also be unset:
Undefines the variable name. If the variable is not defined, the statement is silently ignored. If name is a name of a buil-in variable previously overwritten using the ‘setvar’ statement, the user-supplied definition is removed and the built-in value is restored. Otherwise, if name refers to a built-in variable which was not overridden, this statement does nothing.
This document was generated on June 29, 2019 using makeinfo.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.