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.6 The map statement

rule: map name file delim key kn vn
rule: map [n] file delim key kn vn default

The ‘map’ statement uses file lookup to find a new value for the variable name (or, in its second form, for the positional variable ‘$n’).

Arguments are:

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.

key

The value of the lookup key. Before using, it undergoes backslash interpretation and variable expansion.

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 listed 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. Variable expansion is performed on the key argument (see Variable expansion) 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 variable.
  4. Otherwise, if default is supplied, it becomes the new value of the variable.
  5. Otherwise, the variable 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 ‘$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 – a restricted user shell (split by node):   Section:   Chapter:FastBack: Configuration File   Up: Modifying variables   FastForward: Default Configuration   Contents: Table of ContentsIndex: Concept Index