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.
293 In most circumstances,
297 operator automatically between words that are not separated by white space.
302 follows a quoted or unquoted word or an unquoted word follows a quoted word
303 with no intervening blanks or tabs,
306 is inserted between the two.
307 If an unquoted word immediately follows a
309 and contains a character other than an alphanumeric, underscore,
314 is inserted before the first such character.
317 .B cc -$flags $stem.c
321 .B cc -^$flags $stem^.c
325 redirects the standard output file (file descriptor 1, normally the
326 terminal) to the named
329 appends standard output to the file.
330 The standard input file (file descriptor 0, also normally the terminal)
331 may be redirected from a file by the sequence
333 or from an inline `here document'
335 .BI << eof-marker\f1.
336 The contents of a here document are lines of text taken from the command
337 input stream up to a line containing nothing but the
339 which may be either a quoted or unquoted word.
342 is unquoted, variable names of the form
344 have their values substituted from
349 is followed by a caret
351 the caret is deleted.
354 is quoted, no substitution occurs.
356 Redirections may be applied to a file-descriptor other than standard input
357 or output by qualifying the redirection operator
358 with a number in square brackets.
359 For example, the diagnostic output (file descriptor 2)
360 may be redirected by writing
361 .BR "cc junk.c >[2]junk" .
363 A file descriptor may be redirected to an already open descriptor by writing
366 .BI <[ fd0 = fd1 ]\f1.
368 is a previously opened file descriptor and
370 becomes a new copy (in the sense of
373 A file descriptor may be closed by writing
378 Redirections are executed from left to right.
380 .B cc junk.c >/dev/null >[2=1]
382 .B cc junk.c >[2=1] >/dev/null
383 have different effects: the first puts standard output in
385 and then puts diagnostic output in the same place, where the second
386 directs diagnostic output to the terminal and sends standard output to
388 .SS Compound Commands
389 A pair of commands separated by a pipe operator
392 The standard output of the left command is sent through a pipe
393 to the standard input of the right command.
394 The pipe operator may be decorated
395 to use different file descriptors.
397 connects the output end of the pipe to file descriptor
403 of the left command and input to
405 of the right command.
407 A pair of commands separated by
412 In either case, the left command is executed and its exit status examined.
415 the right command is executed if the left command's status is null.
417 causes the right command to be executed if the left command's status is non-null.
419 The exit status of a command may be inverted (non-null is changed to null, null
420 is changed to non-null) by preceding it with a
425 operator has highest precedence, and is left-associative (i.e. binds tighter
426 to the left than the right).
428 has intermediate precedence, and
432 have the lowest precedence.
436 operator, with precedence equal to
438 causes its operand to be executed in a subshell.
440 Each of the following is a command.
450 is a sequence of commands, separated by
455 if its exit status is null, the
462 The immediately preceding command must have been
465 If its condition was non-zero, the
479 is executed once for each
481 with that argument assigned to
483 If the argument list is omitted,
492 is executed repeatedly until its exit status is non-null.
493 Each time it returns null status, the
498 is taken to give null status.
500 .BI "switch(" argument "){" list }
504 is searched for simple commands beginning with the word
506 (The search is only at the `top level' of the
510 in nested constructs are not found.)
512 is matched against each word following
514 using the pattern-matching algorithm described above, except that
516 and the first characters of
520 need not be matched explicitly.
521 When a match is found, commands in the list are executed up to the next
524 command (at the top level) or the closing brace.
528 Braces serve to alter the grouping of commands implied by operator
532 is a sequence of commands separated by
537 .BI "fn " name { list }
541 The first form defines a function with the given
543 Subsequently, whenever a command whose first argument is
545 is encountered, the current value of
546 the remainder of the command's argument list will be assigned to
548 after saving its current value, and
552 The second form removes
556 .BI "fn " note { list }
561 A function with a special name will be called when
563 receives a corresponding note; see
565 The valid note names (and corresponding notes) are
574 (floating point trap).
577 exits on receiving any signal, except when run interactively,
578 in which case interrupts and quits normally cause
580 to stop whatever it's doing and start reading a new command.
581 The second form causes
583 to handle a signal in the default manner.
585 recognizes an artificial note,
589 is about to finish executing.
591 .IB name = "argument command"
593 Any command may be preceded by a sequence of assignments
594 interspersed with redirections.
595 The assignments remain in effect until the end of the command, unless
596 the command is empty (i.e. the assignments stand alone), in which case
597 they are effective until rescinded by later assignments.
599 .SS Built-in Commands
600 These commands are executed internally by
602 usually because their execution changes or depends on
609 Execute commands from
612 is set for the duration to the remainder of the argument list following
615 is searched for using
618 .BI builtin " command ..."
622 as usual except that any function named
624 is ignored in favor of the built-in meaning.
628 Change the current directory to
630 The default argument is
633 is searched for in each of the directories mentioned in
636 .BI "eval [" "arg ..." "]"
638 The arguments are concatenated separated by spaces into a single string,
643 .BI "exec [" "command ..." "]"
647 replaces itself with the given (non-built-in)
650 .BI "flag " f " [+-]"
664 is a single character, one of the command line flags (see Invocation, below).
666 .BI "exit [" status "]"
668 Exit with the given exit status.
669 If none is given, the current value of
673 .BR "rfork " [ nNeEsfFm ]
675 Become a new process group using
679 is composed of the bitwise OR of the
681 flags specified by the option letters
686 are given, they default to
690 and their meanings are:
727 Wait for the process with the given
732 is given, all outstanding processes are waited for.
734 .BI whatis " name ..."
736 Print the value of each
738 in a form suitable for input to
741 an assignment to any variable,
742 the definition of any function,
745 for any built-in command, or
746 the completed pathname of any executable file.
748 .BI ~ " subject pattern ..."
752 is matched against each
755 If it matches any pattern,
761 Patterns are the same as for file name matching, except that
763 and the first character of
767 need not be matched explicitly.
771 file name matching before the
773 command is executed, so they need not be enclosed in quotation marks.
778 is a list of strings made available to executing binaries by the
781 creates an environment entry for each variable whose value is non-empty,
782 and for each function.
783 The string for a variable entry has the variable's name followed by
786 If the value has more than one component, these
787 are separated by SOH (001)
789 The string for a function is just the
791 input that defines the function.
792 The name of a function in the environment is the function name
798 starts executing it reads variable and function definitions from its
800 .SS Special Variables
801 The following variables are set or used by
804 .TP \w'\fL$promptXX'u
808 argument list during initialization.
811 command or a function is executed, the current value is saved and
813 receives the new argument list.
814 The saved value is restored on completion of the
819 Whenever a process is started asynchronously with
822 is set to its process id.
825 The default directory for
829 The input field separators used in backquote substitutions.
834 environment, it is initialized to blank, tab and newline.
837 The search path used to find commands and input files
841 If not set in the environment, it is initialized by
848 .BR "path=(.\ /bin)" .
853 are maintained together: changes to one will be reflected in the other.
854 .\" Its use is discouraged; instead use
858 .\" containing what's needed.
861 Set during initialization to
868 is run interactively, the first component of
870 is printed before reading each command.
871 The second component is printed whenever a newline is typed and more lines
872 are required to complete the command.
873 If not set in the environment, it is initialized by
874 .BR "prompt=('%\ '\ '\ ')" .
877 Set to the wait message of the last-executed program.
885 Its value is used to control execution in
894 exits at end-of-file of its input or on executing an
896 command with no argument,
903 is started with no arguments it reads commands from standard input.
904 Otherwise its first non-flag argument is the name of a file from which
905 to read commands (but see
908 Subsequent arguments become the initial value of
911 accepts the following command-line flags.
913 .TP \w'\fL-c\ \fIstring\fLXX'u
915 Commands are read from
919 Print out exit status after any command where the status is non-null.
924 is non-null after executing a simple command.
931 is given no arguments and its standard input is a terminal,
932 it runs interactively.
933 Commands are prompted for using
939 is not run interactively.
944 is given or the first character of argument zero is
948 .BR $home/lib/profile ,
949 if it exists, before reading its normal input.
958 Echo input on file descriptor 2 as it is read.
961 Print each simple command before executing it.
964 Print debugging information (internal form of commands
965 as they are executed).
971 ``Rc \- The Plan 9 Shell''.
973 There should be a way to match patterns against whole lists rather than
978 to check the value of
983 Functions that use here documents don't work.
985 Free carets don't get inserted next to keywords.
989 syntax depends on the underlying operating system
990 providing a file descriptor device tree at
993 Some FreeBSD installations
994 does not provide file descriptors greater than 2
1000 /fdescfs /dev/fd fdescfs rw 0 0
1010 ensures causes FreeBSD to mount the file system
1011 automatically at boot time.)