3 rc, cd, eval, exec, exit, flag, rfork, shift, wait, whatis, ., ~ \- command language
20 It executes command lines read from a terminal or a file or, with the
26 A command line is a sequence of commands, separated by ampersands or semicolons
30 terminated by a newline.
31 The commands are executed in sequence
34 does not wait for a command followed by
36 to finish executing before starting
37 the following command.
38 Whenever a command followed by
40 is executed, its process id is assigned to the
48 exits or is terminated, the
52 gets the process's wait message (see
54 it will be the null string if the command was successful.
56 A long command line may be continued on subsequent lines by typing
59 followed by a newline.
60 This sequence is treated as though it were a blank.
61 Backslash is not otherwise a special character.
65 and any following characters up to (but not including) the next newline
66 are ignored, except in quotation marks.
68 A simple command is a sequence of arguments interspersed with I/O redirections.
69 If the first argument is the name of an
73 built-in commands, it is executed by
75 Otherwise if the name starts with a slash
77 it must be the path name of the program to be executed.
78 Names containing no initial slash are searched for in
79 a list of directory names stored in
81 The first executable file of the given name found
84 is the program to be executed.
85 To be executable, the user must have execute permission (see
87 and the file must be either an executable binary
88 for the current machine's CPU type, or a shell script.
89 Shell scripts begin with a line containing the full path name of a shell
95 The first word of a simple command cannot be a keyword unless it is
96 quoted or otherwise disguised.
99 for in while if not switch fn ~ ! @
101 .SS Arguments and Variables
102 A number of constructions may be used where
104 syntax requires an argument to appear.
105 In many cases a construction's
106 value will be a list of arguments rather than a single string.
108 The simplest kind of argument is the unquoted word:
109 a sequence of one or more characters none of which is a blank, tab,
110 newline, or any of the following:
112 # ; & | ^ $ ` ' { } ( ) < >
114 An unquoted word that contains any of the characters
118 is a pattern for matching against file names.
121 matches any sequence of characters,
123 matches any single character, and
125 matches any character in the
127 If the first character of
131 the class is complemented.
134 may also contain pairs of characters separated by
136 standing for all characters lexically between the two.
139 must appear explicitly in a pattern, as must the
140 first character of the path name components
144 A pattern is replaced by a list of arguments, one for each path name matched,
145 except that a pattern matching no names is not replaced by the empty list,
146 but rather stands for itself.
147 Pattern matching is done after all other
160 A quoted word is a sequence of characters surrounded by single quotes
162 A single quote is represented in a quoted word by a pair of quotes
165 Each of the following is an argument.
170 The value of a sequence of arguments enclosed in parentheses is
171 a list comprising the members of each element of the sequence.
172 Argument lists have no recursive structure, although their syntax may
174 The following are entirely equivalent:
176 echo hi there everybody
177 ((echo) (hi there) everybody)
182 .BI $ argument ( subscript )
188 is the name of a variable whose value is substituted.
190 of indirection are possible, but of questionable utility.
192 are lists of strings.
205 elements, in which case the value is empty.
208 is followed by a parenthesized list of subscripts, the
209 value substituted is a list composed of the requested elements (origin 1).
210 The parenthesis must follow the variable name with no spaces.
211 Subscripts can also take the form
215 to indicate a sequence of elements.
216 Assignments to variables are described below.
220 The value is the number of elements in the named variable.
222 never assigned a value has zero elements.
227 The value is a single string containing the components of the named variable
228 separated by spaces. A variable with zero elements yields the empty string.
235 and reads its standard output, splitting it into a list of arguments,
241 is not otherwise set, its value is
250 is executed asynchronously with its standard output or standard input
252 The value of the argument is the name of a file
253 referring to the other end of the pipe.
254 This allows the construction of
255 non-linear pipelines.
256 For example, the following runs two commands
262 to compare their outputs
271 is executed asynchronously with its standard input and
272 output each connected to a pipe. The value of the argument
273 is a pair of file names referring to the two other ends
274 of the pipes, in the order corresponding to the symbols
278 (first the pipe connected to the command's standard output,
279 then the pipe connected to its standard input).
281 .IB argument ^ argument
285 operator concatenates its two operands.
287 have the same number of components, they are concatenated pairwise.
289 then one operand must have one component, and the other must be non-empty,
290 and concatenation is distributive.
296 operator automatically between words that are not separated by white space.
299 .B cc -$flags $stem.c
303 .B cc -^$flags $stem^.c
307 redirects the standard output file (file descriptor 1, normally the
308 terminal) to the named
311 appends standard output to the file.
312 The standard input file (file descriptor 0, also normally the terminal)
313 may be redirected from a file by the sequence
315 or from an inline `here document'
317 .BI << eof-marker\f1.
318 The contents of a here document are lines of text taken from the command
319 input stream up to a line containing nothing but the
321 which may be either a quoted or unquoted word.
324 is unquoted, variable names of the form
326 have their values substituted from
331 is followed by a caret
333 the caret is deleted.
336 is quoted, no substitution occurs.
338 Redirections may be applied to a file-descriptor other than standard input
339 or output by qualifying the redirection operator
340 with a number in square brackets.
341 For example, the diagnostic output (file descriptor 2)
342 may be redirected by writing
343 .BR "cc junk.c >[2]junk" .
345 A file descriptor may be redirected to an already open descriptor by writing
348 .BI <[ fd0 = fd1 ]\f1.
350 is a previously opened file descriptor and
352 becomes a new copy (in the sense of
355 A file descriptor may be closed by writing
360 Redirections are executed from left to right.
362 .B cc junk.c >/dev/null >[2=1]
364 .B cc junk.c >[2=1] >/dev/null
365 have different effects: the first puts standard output in
367 and then puts diagnostic output in the same place, where the second
368 directs diagnostic output to the terminal and sends standard output to
370 .SS Compound Commands
371 A pair of commands separated by a pipe operator
374 The standard output of the left command is sent through a pipe
375 to the standard input of the right command.
376 The pipe operator may be decorated
377 to use different file descriptors.
379 connects the output end of the pipe to file descriptor
385 of the left command and input to
387 of the right command.
389 A pair of commands separated by
394 In either case, the left command is executed and its exit status examined.
397 the right command is executed if the left command's status is null.
399 causes the right command to be executed if the left command's status is non-null.
401 The exit status of a command may be inverted (non-null is changed to null, null
402 is changed to non-null) by preceding it with a
407 operator has highest precedence, and is left-associative (i.e. binds tighter
408 to the left than the right).
410 has intermediate precedence, and
414 have the lowest precedence.
418 operator, with precedence equal to
420 causes its operand to be executed in a subshell.
422 Each of the following is a command.
432 is a sequence of commands, separated by
437 if its exit status is null, the
444 The immediately preceding command must have been
447 If its condition was non-zero, the
461 is executed once for each
463 with that argument assigned to
465 If the argument list is omitted,
474 is executed repeatedly until its exit status is non-null.
475 Each time it returns null status, the
480 is taken to give null status.
482 .BI "switch(" argument "){" list }
486 is searched for simple commands beginning with the word
488 (The search is only at the `top level' of the
492 in nested constructs are not found.)
494 is matched against each word following
496 using the pattern-matching algorithm described above, except that
498 and the first characters of
502 need not be matched explicitly.
503 When a match is found, commands in the list are executed up to the next
506 command (at the top level) or the closing brace.
510 Braces serve to alter the grouping of commands implied by operator
514 is a sequence of commands separated by
519 .BI "fn " name { list }
523 The first form defines a function with the given
525 Subsequently, whenever a command whose first argument is
527 is encountered, the current value of
528 the remainder of the command's argument list will be assigned to
530 after saving its current value, and
534 The second form removes
538 .BI "fn " note { list }
543 A function with a special name will be called when
545 receives a corresponding note; see
547 The valid note names (and corresponding notes) are
556 (floating point trap).
559 exits on receiving any signal, except when run interactively,
560 in which case interrupts and quits normally cause
562 to stop whatever it's doing and start reading a new command.
563 The second form causes
565 to handle a signal in the default manner.
567 recognizes an artificial note,
571 is about to finish executing.
573 .IB name = "argument command"
575 Any command may be preceded by a sequence of assignments
576 interspersed with redirections.
577 The assignments remain in effect until the end of the command, unless
578 the command is empty (i.e. the assignments stand alone), in which case
579 they are effective until rescinded by later assignments.
581 .SS Built-in Commands
582 These commands are executed internally by
584 usually because their execution changes or depends on
591 Execute commands from
594 is set for the duration to the remainder of the argument list following
597 is searched for using
600 .BI builtin " command ..."
604 as usual except that any function named
606 is ignored in favor of the built-in meaning.
610 Change the current directory to
612 The default argument is
615 is searched for in each of the directories mentioned in
618 .BI "eval [" "arg ..." "]"
620 The arguments are concatenated separated by spaces into a single string,
625 .BI "exec [" "command ..." "]"
629 replaces itself with the given (non-built-in)
632 .BI "flag " f " [+-]"
646 is a single character, one of the command line flags (see Invocation, below).
648 .BI "exit [" status "]"
650 Exit with the given exit status.
651 If none is given, the current value of
655 .BR "rfork " [ nNeEsfFm ]
657 Become a new process group using
661 is composed of the bitwise OR of the
663 flags specified by the option letters
668 are given, they default to
672 and their meanings are:
709 Wait for the process with the given
714 is given, all outstanding processes are waited for.
716 .BI whatis " name ..."
718 Print the value of each
720 in a form suitable for input to
723 an assignment to any variable,
724 the definition of any function,
727 for any built-in command, or
728 the completed pathname of any executable file.
730 .BI ~ " subject pattern ..."
734 is matched against each
737 If it matches any pattern,
743 Patterns are the same as for file name matching, except that
745 and the first character of
749 need not be matched explicitly.
753 file name matching before the
755 command is executed, so they need not be enclosed in quotation marks.
760 is a list of strings made available to executing binaries by the
763 creates an environment entry for each variable whose value is non-empty,
764 and for each function.
765 The string for a variable entry has the variable's name followed by
768 If the value has more than one component, these
769 are separated by SOH (001)
771 The string for a function is just the
773 input that defines the function.
774 The name of a function in the environment is the function name
780 starts executing it reads variable and function definitions from its
782 .SS Special Variables
783 The following variables are set or used by
786 .TP \w'\fL$promptXX'u
790 argument list during initialization.
793 command or a function is executed, the current value is saved and
795 receives the new argument list.
796 The saved value is restored on completion of the
801 Whenever a process is started asynchronously with
804 is set to its process id.
807 The default directory for
815 The input field separators used in backquote substitutions.
820 environment, it is initialized to blank, tab and newline.
823 The search path used to find commands and input files
827 If not set in the environment, it is initialized by
834 .BR "path=(.\ /bin)" .
839 are maintained together: changes to one will be reflected in the other.
840 .\" Its use is discouraged; instead use
844 .\" containing what's needed.
847 Set during initialization to
854 is run interactively, the first component of
856 is printed before reading each command.
857 The second component is printed whenever a newline is typed and more lines
858 are required to complete the command.
859 If not set in the environment, it is initialized by
860 .BR "prompt=('%\ '\ '\ ')" .
863 Set to the wait message of the last-executed program.
871 Its value is used to control execution in
880 exits at end-of-file of its input or on executing an
882 command with no argument,
889 is started with no arguments it reads commands from standard input.
890 Otherwise its first non-flag argument is the name of a file from which
891 to read commands (but see
894 Subsequent arguments become the initial value of
897 accepts the following command-line flags.
899 .TP \w'\fL-c\ \fIstring\fLXX'u
901 Commands are read from
905 Print out exit status after any command where the status is non-null.
910 is non-null after executing a simple command.
917 is given no arguments and its standard input is a terminal,
918 it runs interactively.
919 Commands are prompted for using
925 is not run interactively.
930 is given or the first character of argument zero is
934 .BR $home/lib/profile ,
935 if it exists, before reading its normal input.
944 Echo input on file descriptor 2 as it is read.
947 Print each simple command before executing it.
950 Print debugging information (internal form of commands
951 as they are executed).
957 ``Rc \- The Plan 9 Shell''.
959 There should be a way to match patterns against whole lists rather than
964 to check the value of
969 Functions that use here documents don't work.
973 syntax depends on the underlying operating system
974 providing a file descriptor device tree at
977 Some FreeBSD installations
978 does not provide file descriptors greater than 2
984 /fdescfs /dev/fd fdescfs rw 0 0
994 ensures causes FreeBSD to mount the file system
995 automatically at boot time.)
1001 before it can be used as a login shell.