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
267 .IB argument ^ argument
271 operator concatenates its two operands.
273 have the same number of components, they are concatenated pairwise.
275 then one operand must have one component, and the other must be non-empty,
276 and concatenation is distributive.
279 In most circumstances,
283 operator automatically between words that are not separated by white space.
288 follows a quoted or unquoted word or an unquoted word follows a quoted word
289 with no intervening blanks or tabs,
292 is inserted between the two.
293 If an unquoted word immediately follows a
295 and contains a character other than an alphanumeric, underscore,
300 is inserted before the first such character.
303 .B cc -$flags $stem.c
307 .B cc -^$flags $stem^.c
311 redirects the standard output file (file descriptor 1, normally the
312 terminal) to the named
315 appends standard output to the file.
316 The standard input file (file descriptor 0, also normally the terminal)
317 may be redirected from a file by the sequence
319 or from an inline `here document'
321 .BI << eof-marker\f1.
322 The contents of a here document are lines of text taken from the command
323 input stream up to a line containing nothing but the
325 which may be either a quoted or unquoted word.
328 is unquoted, variable names of the form
330 have their values substituted from
335 is followed by a caret
337 the caret is deleted.
340 is quoted, no substitution occurs.
342 Redirections may be applied to a file-descriptor other than standard input
343 or output by qualifying the redirection operator
344 with a number in square brackets.
345 For example, the diagnostic output (file descriptor 2)
346 may be redirected by writing
347 .BR "cc junk.c >[2]junk" .
349 A file descriptor may be redirected to an already open descriptor by writing
352 .BI <[ fd0 = fd1 ]\f1.
354 is a previously opened file descriptor and
356 becomes a new copy (in the sense of
359 A file descriptor may be closed by writing
364 Redirections are executed from left to right.
366 .B cc junk.c >/dev/null >[2=1]
368 .B cc junk.c >[2=1] >/dev/null
369 have different effects: the first puts standard output in
371 and then puts diagnostic output in the same place, where the second
372 directs diagnostic output to the terminal and sends standard output to
374 .SS Compound Commands
375 A pair of commands separated by a pipe operator
378 The standard output of the left command is sent through a pipe
379 to the standard input of the right command.
380 The pipe operator may be decorated
381 to use different file descriptors.
383 connects the output end of the pipe to file descriptor
389 of the left command and input to
391 of the right command.
393 A pair of commands separated by
398 In either case, the left command is executed and its exit status examined.
401 the right command is executed if the left command's status is null.
403 causes the right command to be executed if the left command's status is non-null.
405 The exit status of a command may be inverted (non-null is changed to null, null
406 is changed to non-null) by preceding it with a
411 operator has highest precedence, and is left-associative (i.e. binds tighter
412 to the left than the right).
414 has intermediate precedence, and
418 have the lowest precedence.
422 operator, with precedence equal to
424 causes its operand to be executed in a subshell.
426 Each of the following is a command.
436 is a sequence of commands, separated by
441 if its exit status is null, the
448 The immediately preceding command must have been
451 If its condition was non-zero, the
465 is executed once for each
467 with that argument assigned to
469 If the argument list is omitted,
478 is executed repeatedly until its exit status is non-null.
479 Each time it returns null status, the
484 is taken to give null status.
486 .BI "switch(" argument "){" list }
490 is searched for simple commands beginning with the word
492 (The search is only at the `top level' of the
496 in nested constructs are not found.)
498 is matched against each word following
500 using the pattern-matching algorithm described above, except that
502 and the first characters of
506 need not be matched explicitly.
507 When a match is found, commands in the list are executed up to the next
510 command (at the top level) or the closing brace.
514 Braces serve to alter the grouping of commands implied by operator
518 is a sequence of commands separated by
523 .BI "fn " name { list }
527 The first form defines a function with the given
529 Subsequently, whenever a command whose first argument is
531 is encountered, the current value of
532 the remainder of the command's argument list will be assigned to
534 after saving its current value, and
538 The second form removes
542 .BI "fn " note { list }
547 A function with a special name will be called when
549 receives a corresponding note; see
551 The valid note names (and corresponding notes) are
560 (floating point trap).
563 exits on receiving any signal, except when run interactively,
564 in which case interrupts and quits normally cause
566 to stop whatever it's doing and start reading a new command.
567 The second form causes
569 to handle a signal in the default manner.
571 recognizes an artificial note,
575 is about to finish executing.
577 .IB name = "argument command"
579 Any command may be preceded by a sequence of assignments
580 interspersed with redirections.
581 The assignments remain in effect until the end of the command, unless
582 the command is empty (i.e. the assignments stand alone), in which case
583 they are effective until rescinded by later assignments.
585 .SS Built-in Commands
586 These commands are executed internally by
588 usually because their execution changes or depends on
595 Execute commands from
598 is set for the duration to the remainder of the argument list following
601 is searched for using
604 .BI builtin " command ..."
608 as usual except that any function named
610 is ignored in favor of the built-in meaning.
614 Change the current directory to
616 The default argument is
619 is searched for in each of the directories mentioned in
622 .BI "eval [" "arg ..." "]"
624 The arguments are concatenated separated by spaces into a single string,
629 .BI "exec [" "command ..." "]"
633 replaces itself with the given (non-built-in)
636 .BI "flag " f " [+-]"
650 is a single character, one of the command line flags (see Invocation, below).
652 .BI "exit [" status "]"
654 Exit with the given exit status.
655 If none is given, the current value of
659 .BR "rfork " [ nNeEsfFm ]
661 Become a new process group using
665 is composed of the bitwise OR of the
667 flags specified by the option letters
672 are given, they default to
676 and their meanings are:
713 Wait for the process with the given
718 is given, all outstanding processes are waited for.
720 .BI whatis " name ..."
722 Print the value of each
724 in a form suitable for input to
727 an assignment to any variable,
728 the definition of any function,
731 for any built-in command, or
732 the completed pathname of any executable file.
734 .BI ~ " subject pattern ..."
738 is matched against each
741 If it matches any pattern,
747 Patterns are the same as for file name matching, except that
749 and the first character of
753 need not be matched explicitly.
757 file name matching before the
759 command is executed, so they need not be enclosed in quotation marks.
764 is a list of strings made available to executing binaries by the
767 creates an environment entry for each variable whose value is non-empty,
768 and for each function.
769 The string for a variable entry has the variable's name followed by
772 If the value has more than one component, these
773 are separated by SOH (001)
775 The string for a function is just the
777 input that defines the function.
778 The name of a function in the environment is the function name
784 starts executing it reads variable and function definitions from its
786 .SS Special Variables
787 The following variables are set or used by
790 .TP \w'\fL$promptXX'u
794 argument list during initialization.
797 command or a function is executed, the current value is saved and
799 receives the new argument list.
800 The saved value is restored on completion of the
805 Whenever a process is started asynchronously with
808 is set to its process id.
811 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.
971 Free carets don't get inserted next to keywords.
975 syntax depends on the underlying operating system
976 providing a file descriptor device tree at
979 By default, FreeBSD 5
980 does not provide file descriptors greater than 2
986 /fdescfs /dev/fd fdescfs rw 0 0
996 ensures causes FreeBSD to mount the file system
997 automatically at boot time.)