Node:Miscellaneous, Previous:Current directory, Up:System interface



Miscellaneous

argv Variable
The arguments in the command line used to invoke Q are in argv, which is an array of strings. The first element (i.e. argv 0) is the name of the program running, usually just Q.

If Q is invoked on as file (as in: Q -flags file arg1 ... argn), the value of argv is the file name followed by the non-flags arguments: ["file" "arg1" .. "argn"]. This is compatible with most shells.

env Variable
The "environment" passed to Q (in the Unix sense; see "man 7 environ") is available in the variable env. This is an updatable table, containing strings that are indexed by symbols. When a program is executed, the environment passed to it is taken from env. For example:
Q1> env'TERM
dumb
Q2> env'TERM:="xterm"
Q3> run /bin/sh
$ echo TERM= $TERM
TERM= xterm
To remove an element from the environment, assign NONE to it:
env'TERM:=NONE

exit [code] Function
Terminates the Q program. (Same as the Unix call exit(code).) The default for code is 0.

quit Function
Same as exit 0.

echo [-qn] words... Macro
The echo builtin prints its argument to the output. The -n flag suppresses a final new-line. The -q flag formats each argument as a quoted string literal that can be read in again:
Q1> echo prefix(XX YY)"\012"postfix
prefixXX
postfix prefixYY
postfix
Q2> echo -q prefix(XX YY)"\012"postfix
"prefixXX\npostfix" "prefixYY\npostfix"

quote words... Macro
Informally, the quote macro puts string quotes areound each word in words...; return resulting code evaluates to a vector of strings.

For example quote 4+9 is $(4+9). becomes ["4+9" "is" "$(4+9)."], which evaluates to the vector: ["4+9" "is" "13."].

These routines are used internally (by run and other commands):

glob pattern Function
Return the list of file names that match the pattern. The input should be a string, and the result is a vector of strings. If there is no match, the result is [].
Q1> printf "<%S>" (glob "parse*")
<["parserule.o"
"parsemacros.o"
"parse.o"]>

globlist names Function
Call glob on each element of names, which should be a sequence of strings. Append all the results into one long vector of strings. However, any elements of names that have no matches, are inserted directly into the output list (after parentheses and quoting characters have been removed).
Q2> globlist ["*.b" "parse*" "foo\"+\"(abc)"]
*.b
parserule.o
parsemacros.o
parse.o
foo+abc
This behavior mimics that used by /bin/sh.