GNU Rush legacy configuration syntax (split by node):   Section:   Chapter:FastBack: Rule   Up: Transformations   FastForward: Include   Contents: Table of ContentsIndex: Concept Index

3.2.5 Set and unset variables

The ‘setvar’ statement allows you to define or redefine variables. The syntax is:

Rule Config: setvar[name] pattern

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:

Rule Config: unsetvar[name]

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.

GNU Rush legacy configuration syntax (split by node):   Section:   Chapter:FastBack: Rule   Up: Transformations   FastForward: Include   Contents: Table of ContentsIndex: Concept Index