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

3.2.4 Map

The ‘map’ statement uses file lookup to find a new value for the command line word.

Rule Config: map[n] file delim pattern kn vn
Rule Config: map[n] file delim pattern kn vn default

Arguments are:

n

Argument index, as in indexing.

file

Name of the map file. It must begin with ‘/’ or ‘~/’. Before using, the file permissions and ownership are checked using the procedure described in security checks.

delim

A string containing allowed field delimiters.

pattern

The value of the lookup key. Before using, it is expanded as described in patterns.

kn

Number of the key field in file. Fields are numbered starting from 1.

vn

Number of the value field.

default

If supplied, this value is used as a replacement value, when the key was not found in file.

The map file consists of records, separated by newline characters (in other words, a record occupies one line). Each record consists of fields, separated by delimiters, given in delim argument. If delim contains a space character, then fields may be delimited by any amount of whitespace characters (spaces and/or tabulations). Otherwise, exactly one delimiter delimits fields.

Fields are numbered starting from 1.

The map action works as follows:

  1. The pattern argument is expanded as described in patterns and the resulting value is used as lookup key.
  2. The file is scanned for a record whose knth field matches the lookup key.
  3. If such a record is found, the value of its vnth field is assigned to the nth command line word (see indexing, for a description of n).
  4. Otherwise, if default is supplied, it becomes the new value of the nth word.
  5. Otherwise, the nth word remains unchanged.

For example, suppose that the file /etc/passwd.rush has the same syntax as the system passwd file (see Password File in passwd(5) man page). Then, the following statement will replace ‘argv[0]’ with the value of ‘shell’ field, using the current user name as a key:

map[0] /etc/passwd.rush : ${user} 1 7

See also Interactive, for another example of using this statement.

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