0 .TF "-c string"
-c " string" Commands are read from string.
-d Dump parsed commands before execution.
-e Fail if a top level command does.
-n Parse but do not execute.
-x Print each simple command before executing it.
If invoked without arguments mash first runs the commands found in /lib/mashinit .
A number-sign (#) and any following characters up to (but not including) the next newline are ignored, except in quotation marks.
The keywords are .EX case else fn for hd if in len rescue tl while
The simplest kind of word is the unquoted word: a sequence of one or more characters none of which is a blank, tab, newline, or any of the following: .EX # : ; ! ~ @ & | ^ $ = " ` ' { } ( ) < > An unquoted word that contains any of the characters * , ? or [ is a pattern for matching against file names. The character * matches any sequence of characters, ? matches any single character, and [ class ] matches any character in the class. The class may also contain pairs of characters separated by - , standing for all characters lexically between the two. The character / must appear explicitly in a pattern. A pattern is replaced by a list of words, one for each path name matched, except that a pattern matching no names is not replaced by the empty list, but rather stands for itself. Pattern matching is done after all other operations. Thus, .EX x=/tmp; echo $x^/*.c; matches /tmp/*.c , rather than matching /*.c and then prefixing /tmp .
A quoted word is a sequence of characters surrounded by single quotes ( ' ). A single quote is escaped with a backslash.
Each of the following is a word.
0
$ identifier
The identifier after the $ is the name of a variable whose value is substituted. Variable values are lists of strings. It is an error if the named variable has never been assigned a value.
$ number
See the description of rules for the mash-make (1) builtin.
$"\c identifier
The value is a single string containing the components of the named variable separated by spaces.
`{ commands }
mash executes the commands and reads the standard output, splitting it into a list of words, using the whitespace characters (space, tab, newline and carriage return) as separators.
"{\c commands }
mash executes the commands and reads the standard output, splitting it into a list of words, using the whitespace characters (space, tab, newline and carriage return) as separators.
<{ commands }
>{ commands }
The commands are executed asynchronously with their standard output or standard input connected to a pipe. The value of the word is the name of a file referring to the other end of the pipe. This allows the construction of non-linear pipelines. For example, the following runs two commands old and new and uses cmp to compare their outputs .EX cmp <{old} <{new};
( expr ) mash evaluates expr as an expression. The value is a (possibly null) list of words. Expressions are described in detail below.
word ^ word
The ^ operator concatenates its two operands. If either operand is a singleton, the concatenation is distributive. Otherwise the lists are concatenated pairwise.
is equivalent to
limbo -^$flags $stem^.bEach of the following is a command.
0
if ( expr ) command1
if ( expr ) command1 else command2
The expr is evaluated and if the result is not null, then command1 is executed. In the second form command2 is executed if the result is null.
for ( name in list ) command
The command is executed once for each word in list with that word assigned to name .
while ( expr ) command
The expr is evaluated repeatedly until its value is null. Each time it evaluates to non-null, the command is executed.
case expr { pattern-list => command ... }
case expr-list { pattern => command ... }
In the first form of the command the expr is matched against a series of lists of regular expressions (See regex (2)). The command associated with the matching expression is executed. In the second form the command associated with the first pattern to match one of the words in expr-list is executed. An expr-list will never match a pattern-list .
{ commands }
@{ commands }
Braces serve to alter the grouping of commands implied by operator priorities. The body is a sequence of commands separated by & or ; . The second form is executed with a new scope. Either form can be followed by redirections.
fn name { list }
fn name
The first form defines a function with the given name . Subsequently, whenever a command whose first word is name is encountered, the current value of the remainder of the command's word list will be assigned to the local variable args , in a new scope, and mash will execute the list. The second form removes name 's function definition.
name = list
name := list
The first form is an assignment to a variable. If the name is currently defined as a local variable its value will be updated. Otherwise a global variable with the given name will be defined or updated. The second form is an explicit definition or update of a local variable.
list : list
list : list { commands }
word :~ word { commands }
These forms define dependencies and rules for the make loadable builtin. The first form defines a simple dependency, the second a dependency with an explicit rule. The third form defines an implicit rule where the left-hand word is a file pattern, the right-hand word is the prerequisite. The right-hand word and the commands can contain references to the characters matched by the * meta-character in the pattern ( $1 evaluates to the characters matched by the first * , $2 the second and so on; $0 is the entire match).
0
( " expr " )
Parentheses are used for grouping.
hd " expr"
tl " expr"
len " expr"
! " expr"
hd is the first element of a list, tl the remainder. len is the length of a list. Both evaluate to the null list if their operand is a null list. ! is the not operator and evaluates to true for a null list or to a null list otherwise.
expr " ^ " expr
expr " :: " expr
expr " == " expr
expr " != " expr
expr " ~ " expr
^ is concatenation (as defined above), :: is list concatenation, == and != are the equality operators evaluating to true or the null list, depending on the equality or inequality of the two operands. ~ is the match operator, true if a singleton string matches one of a list of regular expressions, or one of a list of strings matches a regular expression. (If neither operand is a singleton it evaluates to the null list.) ^ has the highest precedence, followed by :: followed by the other three. All associate to the left except :: .
0
env
Print global and local variables. Global variables are displayed using a name = value format, and local variables using a name := value format.
eval
Concatenate arguments and use as mash input.
exit
Cause mash to raise an "exit" exception.
load file
Load a builtin module. The file must be a module with type Mashbuiltin . The argument file is assumed to contain a path to the loadable module. If no such module is found then the string /dis/lib/mash/ is prepended to file and the load is retried.
prompt
prompt text
prompt "text contin"
When called with no arguments causes the current value of the mash prompt to be printed to standard output. The default value is mash% . The second form sets a new prompt. The final form sets a new prompt and additionally a continuation string. Initially the continuation string is set to a single tab character. Mash uses the continuation string in place of the prompt string to indicate that the preceding line has been continued by escaping with a final backslash ( \e ) character.
quote args...
Print arguments quoted as input for mash .
"run -" [ denx "] file [arg...]"
Interpret a file as input to mash .
time "cmd [arg...]"
Time the execution of a command. The total execution time is reported in seconds and on standard error when the command completes.
whatis name
Print variable, function or builtin. The object given by name is described on standard output in a format that reflects its type.
The make loadable builtin provides `make` functionality. The tk loadable builtin provides control over some of the visual elements of a mash window.
Tom Duff, ``Rc - The Plan 9 Shell'', in the "Plan 9 Programmer's Manual", Second Edition, Volume 2.