![]() |
![]()
| ![]() |
![]()
NAMErc, cd, eval, exec, exit, flag, rfork, shift, wait, whatis, ., ~ - command language SYNOPSISrc [ -srdiIlxepvV ] [ -c command ] [ file [ arg ... ]] DESCRIPTIONRc is the Plan 9 shell. It executes command lines read from a terminal or a file or, with the -c flag, from rc's argument list. Command LinesA command line is a sequence of commands, separated by ampersands or semicolons (& or ;), terminated by a newline. The commands are executed in sequence from left to right. Rc does not wait for a command followed by & to finish executing before starting the following command. Whenever a command followed by & is executed, its process id is assigned to the rc variable $apid. Whenever a command not followed by & exits or is terminated, the rc variable $status gets the process's wait message (see it will be the null string if the command was successful. A long command line may be continued on subsequent lines by typing a backslash (\) followed by a newline. This sequence is treated as though it were a blank. Backslash is not otherwise a special character. A number-sign (#) and any following characters up to (but not including) the next newline are ignored, except in quotation marks. Simple CommandsA simple command is a sequence of arguments interspersed with I/O redirections. If the first argument is the name of an rc function or of one of rc's built-in commands, it is executed by rc. Otherwise if the name starts with a slash (/), it must be the path name of the program to be executed. Names containing no initial slash are searched for in a list of directory names stored in $path. The first executable file of the given name found in a directory in $path is the program to be executed. To be executable, the user must have execute permission (see and the file must be either an executable binary for the current machine's CPU type, or a shell script. Shell scripts begin with a line containing the full path name of a shell (usually /bin/rc), prefixed by The first word of a simple command cannot be a keyword unless it is quoted or otherwise disguised. The keywords are for in while if not switch fn ~ ! @ Arguments and VariablesA number of constructions may be used where rc's syntax requires an argument to appear. In many cases a construction's value will be a list of arguments rather than a single string. The simplest kind of argument is the unquoted word: a sequence of one or more characters none of which is a blank, tab, newline, or any of the following: # ; & | ^ $ ` ' { } ( ) < >An unquoted word that contains any of the characters * ? [ 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. If the first character of class is ~, the class is complemented. 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, as must the first character of the path name components . and ... A pattern is replaced by a list of arguments, 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, x=/tmp echo $x^/*.cmatches /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 represented in a quoted word by a pair of quotes (''). Each of the following is an argument. (arguments)
echo hi there everybody ((echo) (hi there) everybody) $argument $argument(subscript)
$#argument
$"argument
`{command}
<{command} >{command}
cmp <{old} <{new} <>{command}
argument^argument
Free CaretsRc will insert the ^ operator automatically between words that are not separated by white space. Thus
is equivalent to
I/O RedirectionsThe sequence >file redirects the standard output file (file descriptor 1, normally the terminal) to the named file; >>file appends standard output to the file. The standard input file (file descriptor 0, also normally the terminal) may be redirected from a file by the sequence <file, or from an inline `here document' by the sequence <<eof-marker. The contents of a here document are lines of text taken from the command input stream up to a line containing nothing but the eof-marker, which may be either a quoted or unquoted word. If eof-marker is unquoted, variable names of the form $word have their values substituted from rc's environment. If $word is followed by a caret (^), the caret is deleted. If eof-marker is quoted, no substitution occurs. Redirections may be applied to a file-descriptor other than standard input or output by qualifying the redirection operator with a number in square brackets. For example, the diagnostic output (file descriptor 2) may be redirected by writing cc junk.c >[2]junk. A file descriptor may be redirected to an already open descriptor by writing >[fd0=fd1] or <[fd0=fd1]. Fd1 is a previously opened file descriptor and fd0 becomes a new copy (in the sense of of it. A file descriptor may be closed by writing >[fd0=] or <[fd0=]. Redirections are executed from left to right. Therefore, cc junk.c >/dev/null >[2=1] and cc junk.c >[2=1] >/dev/null have different effects: the first puts standard output in /dev/null and then puts diagnostic output in the same place, where the second directs diagnostic output to the terminal and sends standard output to /dev/null. Compound CommandsA pair of commands separated by a pipe operator (|) is a command. The standard output of the left command is sent through a pipe to the standard input of the right command. The pipe operator may be decorated to use different file descriptors. |[fd] connects the output end of the pipe to file descriptor fd rather than 1. |[fd0=fd1] connects output to fd1 of the left command and input to fd0 of the right command. A pair of commands separated by && or || is a command. In either case, the left command is executed and its exit status examined. If the operator is && the right command is executed if the left command's status is null. || causes the right command to be executed if the left command's status is non-null. The exit status of a command may be inverted (non-null is changed to null, null is changed to non-null) by preceding it with a !. The | operator has highest precedence, and is left-associative (i.e. binds tighter to the left than the right). ! has intermediate precedence, and && and || have the lowest precedence. The unary @ operator, with precedence equal to !, causes its operand to be executed in a subshell. Each of the following is a command. if ( list ) command
if not command
for(name in arguments) command for(name) command
while(list) command
switch(argument){list}
{list}
fn name{list} fn name
fn note{list}
fn note
name=argument command
Built-in CommandsThese commands are executed internally by rc, usually because their execution changes or depends on rc's internal state. . file ...
builtin command ...
cd [dir]
eval [arg ...]
exec [command ...]
flag f [+-]
exit [status]
rfork [nNeEsfFm]
shift [n]
wait [pid]
whatis name ...
~ subject pattern ...
EnvironmentThe environment is a list of strings made available to executing binaries by the kernel. Rc creates an environment entry for each variable whose value is non-empty, and for each function. The string for a variable entry has the variable's name followed by = and its value. If the value has more than one component, these are separated by SOH (001) characters. The string for a function is just the rc input that defines the function. The name of a function in the environment is the function name preceded by When rc starts executing it reads variable and function definitions from its environment. Special VariablesThe following variables are set or used by rc.
InvocationIf rc is started with no arguments it reads commands from standard input. Otherwise its first non-flag argument is the name of a file from which to read commands (but see -c below). Subsequent arguments become the initial value of $*. Rc accepts the following command-line flags.
SOURCE/src/cmd/rc SEE ALSOTom Duff, ``Rc - The Plan 9 Shell''. BUGSThere should be a way to match patterns against whole lists rather than just single strings. Using ~ to check the value of $status changes $status. Functions that use here documents don't work. The <{command} syntax depends on the underlying operating system providing a file descriptor device tree at /dev/fd. Some FreeBSD installations does not provide file descriptors greater than 2 in /dev/fd. To fix this, add
to /etc/fstab, and then mount /dev/fd. (Adding the line to fstab ensures causes FreeBSD to mount the file system automatically at boot time.) Some systems require /bin/rc to be listed in /etc/shells before it can be used as a login shell.
|