1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)sh.1 5.1 (Berkeley) 3/7/91
37 .TH SH 1 "March 7, 1991"
45 .de d \" begin display
55 .de c \" command, etc.
61 .de b \" begin builtin command
66 ash, sh, ., break, case, cd, command, continue, eval, exec, exit, export, for, getopts, hash, if, jobs, local, read, readonly, return, set, setvar, shift, trap, umask, unset, wait, while \- a shell
80 Copyright 1989 by Kenneth Almquist.
85 with features similar to those of the System V shell.
86 This manual page lists all the features of
88 but concentrates on the ones not in other shells.
92 options is given, then the shell executes the specified shell command.
95 flag cause the shell to read commands from the standard input (after
96 executing any command specified with the
103 options are set, then the first
105 is taken as the name of a file to read commands from.
106 If this is impossible because there are no arguments following
111 flag and will read commands from the standard input.
113 The shell sets the initial value of the positional parameters from the
117 used as the name of a file of commands is deleted.
119 The flags (other than
121 are set by preceding them with ``-'' and cleared by preceding them
124 builtin command for a list of flags.
125 If no value is specified for the
129 flag is set, and the standard input and output of the shell
130 are connected to terminals, then the
133 If no value is specified for the
137 flag will be set if the
141 When the shell is invoked with the
143 option, it is good practice to include the
145 flag if the command was entered interactively by a user.
146 For compatibility with the System V shell, the
148 option should come after the
152 If the first character of argument zero to the shell is ``-'',
153 the shell is assumed to be a login shell, and the files
157 are read if they exist.
158 If the environment variable SHINIT is set on entry to the shell,
159 the commands in SHINIT are normally parsed and executed. SHINIT is
160 not examined if the shell is a login shell, or if it the shell is running a
161 shell procedure. (A shell is considered to be running a shell
162 procedure if neither the
167 .h "Control Structures"
170 is a sequence of zero or more commands separated by newlines,
171 semicolons, or ampersands, and optionally terminated by one of these
172 three characters. (This differs from the System V shell, which
173 requires a list to contain at least one command in most cases.) The
174 commands in a list are executed in the order they are written.
175 If command is followed by an ampersand, the shell starts the command
176 and immediately proceed onto the next command; otherwise it waits
177 for the command to terminate before proceeding to the next one.
179 ``&&'' and ``||'' are binary operators.
180 ``&&'' executes the first command, and then executes the second command
181 iff the exit status of the first command is zero. ``||'' is similar,
182 but executes the second command iff the exit status of the first command
183 is nonzero. ``&&'' and ``||'' both have the same priority.
185 The ``|'' operator is a binary operator which feeds the standard output
186 of the first command into the standard input of the second command.
187 The exit status of the ``|'' operator is the exit status of the second
188 command. ``|'' has a higher priority than ``||'' or ``&&''.
198 \fBthen\fR list ] ...
212 The two lists are executed repeatedly while the exit status of the first
215 command is similar, but has the word
219 repeats until the exit status of the first list
226 \fBfor\fR variable \fBin\fR word...
230 The words are expanded, and then the list is executed repeatedly with
231 the variable set to each word in turn.
245 \fBcontinue\fR [ num ]
256 continues with the next iteration of the
259 These are implemented as builtin commands.
265 \fBcase\fR word \fBin\fR
266 pattern\fB)\fR list \fB;;\fR
270 The pattern can actually be one or more patterns (see
272 below), separated by ``|'' characters.
274 Commands may be grouped by writing either
280 \fB{\fR list; \fB}\fR
282 The first of these executes the commands in a subshell.
284 A function definition looks like
286 name \fB( )\fR command
288 A function definition is an executable statement; when executed it installs
291 and returns an exit status of zero.
292 The command is normally a list enclosed between ``{'' and ``}''.
294 Variables may be declared to be local to a function by using a
296 command. This should appear as the first staement of a function,
299 \fBlocal\fR [ variable | \fB-\fR ] ...
302 is implemented as a builtin command.
304 When a variable is made local, it inherits the initial value and
305 exported and readonly flags from the variable with the same name in the
306 surrounding scope, if there is one. Otherwise, the variable is
309 uses dynamic scoping, so that if you make the variable
313 which then calls function
315 references to the variable
319 will refer to the variable
323 not to the global variable named
326 The only special parameter that can be made local is ``\fB-\fR''.
327 Making ``\fB-\fR'' local any shell options that are changed via the
329 command inside the function to be restored to their original values
330 when the function returns.
336 \fBreturn\fR [ exitstatus ]
338 It terminates the currently executing function.
340 is implemented as a builtin command.
342 A simple command is a sequence of words. The execution of a simple
343 command proceeds as follows. First, the leading words of the form
344 ``name=value'' are stripped off and assigned to the environment of
345 the command. Second, the words are expanded. Third, the first
346 remaining word is taken as the command name that command is located.
347 Fourth, any redirections are performed. Fifth, the command is
348 executed. We look at these operations in reverse order.
350 The execution of the command varies with the type of command.
351 There are three types of commands: shell functions, builtin commands,
354 When a shell function is executed, all of the shell positional parameters
355 (except $0, which remains unchanged) are set to the parameters to the shell
356 function. The variables which are explicitly placed in the environment
357 of the command (by placing assignments to them before the function name)
358 are made local to the function and are set to values given.
359 Then the command given in the function definition is executed.
360 The positional parameters are restored to their original values when
361 the command completes.
363 Shell builtins are executed internally to the shell, without spawning
366 When a normal program is executed, the shell runs the program, passing
367 the parameters and the environment to the program. If the program is
368 a shell procedure, the shell will interpret the program in a subshell.
369 The shell will reinitialize itself in this case, so that the effect
370 will be as if a new shell had been invoked to handle the shell procedure,
371 except that the location of commands located in the parent shell will
372 be remembered by the child. If the program is a file beginning with
373 ``#!'', the remainder of the first line specifies an interpreter for
374 the program. The shell (or the operating system, under Berkeley UNIX)
375 will run the interpreter in this case. The arguments to the interpreter
376 will consist of any arguments given on the first line of the program,
377 followed by the name of the program, followed by the arguments passed
380 Input/output redirections can be intermixed with the words in a simple
381 command and can be placed following any of the other commands. When
382 redirection occurs, the shell saves the old values of the file descriptors
383 and restores them when the command completes. The ``<'', ``>'', and ``>>''
384 redirections open a file for input, output, and appending, respectively.
385 The ``<&digit'' and ``>&digit'' makes the input or output a duplicate
386 of the file descriptor numbered by the digit. If a minus sign is used
387 in place of a digit, the standard input or standard output are closed.
389 The ``<<\ word'' redirection
393 As the shell encounters ``<<'' redirections, it collects them. The
394 next time it encounters an unescaped newline, it reads the documents
395 in turn. The word following the ``<<'' specifies the contents of the
396 line that terminates the document. If none of the quoting methods
397 ('', "", or \e) are used to enter the word, then the document is treated
398 like a word inside double quotes: ``$'' and backquote are expanded
399 and backslash can be used to escape these and to continue long lines.
400 The word cannot contain any variable or command substitutions, and
401 its length (after quoting) must be in the range of 1 to 79 characters.
402 If ``<<-'' is used in place of ``<<'', then leading tabs are deleted
403 from the lines of the document. (This is to allow you do indent shell
404 procedures containing here documents in a natural fashion.)
406 Any of the preceding redirection operators may be preceded by a single
407 digit specifying the file descriptor to be redirected. There cannot
408 be any white space between the digit and the redirection operator.
410 When locating a command, the shell first looks to see if it has a
411 shell function by that name. Then, if PATH does not contain an
412 entry for "%builtin", it looks for a builtin command by that name.
413 Finally, it searches each entry in PATH in turn for the command.
415 The value of the PATH variable should be a series of entries separated
417 Each entry consists of a directory name, or a directory name followed
418 by a flag beginning with a percent sign.
419 The current directory should be indicated by an empty directory name.
421 If no percent sign is present, then the entry causes the shell to
422 search for the command in the specified directory. If the flag is
423 ``%builtin'' then the list of shell builtin commands is searched.
424 If the flag is ``%func'' then the directory is searched for a file which
425 is read as input to the shell. This file should define a function
426 whose name is the name of the command being searched for.
428 Command names containing a slash are simply executed without performing
429 any of the above searches.
431 The environment of a command is a set of name/value pairs. When the
432 shell is invoked, it reads these names and values, sets the shell
433 variables with these names to the corresponding values, and marks
434 the variables as exported. The
436 command can be used to mark additional variables as exported.
438 The environment of a command is constructed by constructing name/value
439 pairs from all the exported shell variables, and then modifying this
440 set by the assignments which precede the command, if any.
442 The process of evaluating words when a shell procedure is executed is
445 Expansion consists of four steps: variable substitution, command
446 substitution, word splitting, and file name generation. If a word
447 is the expression following the word
449 in a case statement, the file name
450 which follows a redirection symbol, or an assignment to the environment
451 of a command, then the word cannot be split into multiple words. In
452 these cases, the last two steps of the expansion process are omitted.
453 .h "Variable Substitution"
455 .h "Command Substitution"
457 accepts two syntaxes for command substitution:
465 Either of these may be included in a word.
466 During the command substitution process, the command (syntactly a
468 will be executed and anything that the command writes to the standard
469 output will be captured by the shell. The final newline (if any) of
470 the output will be deleted; the rest of the output will be substituted
471 for the command in the word.
473 When the value of a variable or the output of a command is substituted,
474 the resulting text is subject to word splitting, unless the dollar sign
475 introducing the variable or backquotes containing the text were enclosed
476 in double quotes. In addition, ``$@'' is subject to a special type of
477 splitting, even in the presence of double quotes.
479 Ash uses two different splitting algorithms. The normal approach, which
480 is intended for splitting text separated by which space, is used if the
481 first character of the shell variable IFS is a space. Otherwise an alternative
482 experimental algorithm, which is useful for splitting (possibly empty)
483 fields separated by a separator character, is used.
485 When performing splitting, the shell scans the replacement text looking
486 for a character (when IFS does not begin with a space) or a sequence of
487 characters (when IFS does begin with a space), deletes the character or
488 sequence of characters, and spits the word into two strings at that
489 point. When IFS begins with a space, the shell deletes either of the
490 strings if they are null. As a special case, if the word containing
491 the replacement text is the null string, the word is deleted.
493 The variable ``$@'' is special in two ways. First, splitting takes
494 place between the positional parameters, even if the text is enclosed
495 in double quotes. Second, if the word containing the replacement
496 text is the null string and there are no positional parameters, then
497 the word is deleted. The result of these rules is that "$@" is
498 equivalent to "$1" "$2" ... "$\fIn\fR", where \fIn\fR is the number of
499 positional parameters. (Note that this differs from the System V shell.
500 The System V documentation claims that "$@" behaves this way; in fact
501 on the System V shell "$@" is equivalent to "" when there are no
502 positional paramteters.)
503 .h "File Name Generation"
506 flag is set, file name generation is performed after word splitting is
507 complete. Each word is viewed as a series of patterns, separated by
508 slashes. The process of expansion replaces the word with the names of
509 all existing files whose names can be formed by replacing each pattern
510 with a string that matches the specified pattern. There are two
511 restrictions on this: first, a pattern cannot match a string containing
512 a slash, and second, a pattern cannot match a string starting with a
513 period unless the first character of the pattern is a period.
515 If a word fails to match any files and the
517 flag is not set, then the word will be left unchanged (except that the
518 meta-characters will be converted to normal characters). If the
520 flag is set, then the word is only left unchanged if none
521 of the patterns contain a character that can match anything besides
522 itself. Otherwise the
524 flag forces the word to be replaced with the names of the files that it
525 matches, even if there are zero names.
529 consists of normal characters, which match themselves, and meta-characters.
530 The meta-characters are ``!'', ``*'', ``?'', and ``[''. These characters lose
531 there special meanings if they are quoted. When command or variable
532 substitution is performed and the dollar sign or back quotes are not
533 double quoted, the value of the variable or the output of the command
534 is scanned for these characters and they are turned into meta-characters.
536 Two exclamation points at the beginning of a pattern function as a ``not''
537 operator, causing the pattern to match any string that the remainder of
540 match. Other occurances of exclamation points in a pattern match
541 exclamation points. Two exclamation points are required rather than one
542 to decrease the incompatibility with the System V shell (which does not
543 treat exclamation points specially).
545 An asterisk (``*'') matches any string of characters.
546 A question mark matches any single character.
547 A left bracket (``['') introduces a character class. The end of the
548 character class is indicated by a ``]''; if the ``]'' is missing then
549 the ``['' matches a ``['' rather than introducing a character class.
550 A character class matches any of the characters between the square
551 brackets. A range of characters may be specified using a minus sign.
552 The character class may be complemented by making an exclamation point
553 the first character of the character class.
555 To include a ``]'' in a character class, make it the first character listed
556 (after the ``!'', if any).
557 To include a minus sign, make it the first or last character listed.
558 .h "The /u Directory"
559 By convention, the name ``/u/user'' refers to the home directory of the
560 specified user. There are good reasons why this feature should be supported
561 by the file system (using a feature such as symbolic links) rather than
564 is capable of performing this mapping if the file system doesn't.
565 If the mapping is done by
569 flag will turn it off.
572 silently discards nul characters. Any other character will be handled
575 including characters with the high order bit set.
576 .h "Job Names and Job Control"
579 refers to a process created by a shell command, or in the case of a
580 pipeline, to the set of processes in the pipeline. The ways to refer
588 The first form identifies a job by job number.
589 When a command is run,
591 assigns it a job number
592 (the lowest unused number is assigned).
593 The second form identifies a job by giving a prefix of the command used
594 to create the job. The prefix must be unique. If there is only one job,
595 then the null prefix will identify the job, so you can refer to the job
596 by writing ``%''. The third form refers to the \fIcurrent job\fR. The
597 current job is the last job to be stopped while it was in the foreground.
598 (See the next paragraph.) The last form identifies a job by giving the
599 process id of the last process in the job.
601 If the operating system that
603 is running on supports job control,
605 will allow you to use it.
606 In this case, typing the suspend character (typically ^Z) while running
607 a command will return you to
609 and will make the suspended command the current job. You can then continue
610 the job in the background by typing
612 or you can continue it in the foreground by typing
615 If the shell variable ATTY is set, and the shell variable TERM is not
616 set to ``emacs'', then \fIash\fR generates appropriate escape sequences
620 By tradition, an exit status of zero means that a command has succeeded
621 and a nonzero exit status indicates that the command failed. This is
622 better than no convention at all, but in practice it is extremely useful
623 to allow commands that succeed to use the exit status to return information
624 to the caller. A variety of better conventions have been proposed, but
625 none of them has met with universal approval. The convention used by
626 \fIash\fR and all the programs included in the \fIash\fR distribution is
633 129-... Command terminated by a signal.
635 The \fIalternate success\fR return is used by commands to indicate various
636 conditions which are not errors but which can, with a little imagination,
637 be conceived of as less successful than plain success. For example,
639 returns 1 when the tested condition is false and
641 returns 1 when there are no more options.
642 Because this convention is not used universally, the
646 causes the shell to exit when a command returns 1 even though that
647 contradicts the convention described here.
649 When a command is terminated by a signal, the uses 128 plus the signal
650 number as the exit code for the command.
651 .h "Builtin Commands"
652 This concluding section lists the builtin commands which are builtin
653 because they need to perform some operation that can't be performed by a
654 separate process. In addition to these, there are several other commands
664 which can optionally be compiled into the shell. The builtin
665 commands described below that accept options use the System V Release 2
674 Continue the specified jobs (or the current job if no jobs are given)
676 This command is only available on systems with Bekeley job control.
678 .IR "command arg" ...
680 Execute the specified builtin command. (This is useful when you have a
681 shell function with the same name as a builtin command.)
687 Switch to the specified directory (default $HOME).
688 If the an entry for CDPATH appears in the environment of the cd command
689 or the shell variable CDPATH is set and the directory name does not
690 begin with a slash, then the directories listed in CDPATH will be
691 searched for the specified directory. The format of CDPATH is the
692 same as that of PATH.
693 In an interactive shell, the cd command will print out the name of the
694 directory that it actually switched to if this is different from the
695 name that the user gave. These may be different either because
696 the CDPATH mechanism was used or because a symbolic link was crossed.
697 .\" .b ".\fI\h'0.1i'file"
698 .\" Cawf can't do \h'0.1i'
702 The commands in the specified file are read and executed by the shell.
703 A path search is not done to find the file because the directories in
704 PATH generally contain files that are intended to be executed, not read.
708 The strings are parsed as shell commands and executed.
709 (This differs from the System V shell, which concatenates the arguments
710 (separated by spaces) and parses the result as a single command.)
713 .IR "command arg" ...
719 the shell process is replaced with the specified program (which must be a real
720 program, not a shell builtin or function).
721 Any redirections on the exec command are marked as permanent, so that they
722 are not undone when the exec command finishes.
723 If the command is not found, the exec command causes the shell to exit.
729 Terminate the shell process. If
731 is given it is used as the
732 exit status of the shell; otherwise the exit status of the preceding
737 The specified names are exported so that they will appear in the environment
738 of subsequent commands. The only way to un-export a variable is to unset it.
740 allows the value of a variable to be set at the same time it is exported
743 \fBexport\fR name=value
745 With no arguments the export command lists the names of all exported variables.
751 Move the specified job or the current job to the foreground.
752 This command is only available on systems with Bekeley job control.
764 The shell maintains a hash table which remembers the locations of
765 commands. With no arguments whatsoever, the hash command prints
766 out the contents of this table. Entries which have not been looked
769 command are marked with an asterisk; it is possible for these entries
772 With arguments, the hash command removes the specified commands from
773 the hash table (unless they are functions) and then locates them.
778 prints the locations of the commands as it finds them.
783 command to delete all the entries in the hash table except for
790 Print the process id's of the processes in the job. If the job argument
791 is omitted, use the current job.
794 This command lists out all the background processes which are children
795 of the current shell process.
798 Print the current directory. The builtin command may differ from the
799 program of the same name because the builtin command remembers what
800 the current directory is rather than recomputing it each time. This
801 makes it faster. However, if the current directory is renamed, the
802 builtin version of pwd will continue to print the old name for the
814 The prompt is printed if the
816 option is specified and the standard input is a terminal. Then a
817 line is read from the standard input. The trailing newline is deleted
818 from the line and the line is split as described
819 in the section on word splitting above, and the pieces are assigned to
820 the variables in order. If there are more pieces than variables, the
821 remaining pieces (along with the characters in IFS that separated them)
822 are assigned to the last variable. If there are more variables than
823 pieces, the remaining variables are assigned the null string.
827 option causes any backslashes in the input to be treated specially.
828 If a backslash is followed by a newline, the backslash and the newline
829 will be deleted. If a backslash is followed by any other character,
830 the backslash will be deleted and the following character will be treated
831 as though it were not in IFS, even if it is.
835 The specified names are marked as read only, so that they cannot be
836 subsequently modified or unset.
838 allows the value of a variable to be set at the same time it is marked
841 \fBreadonly\fR name=value
843 With no arguments the readonly command lists the names of all
859 command performs three different functions.
861 With no arguments, it lists the values of all shell variables.
863 If options are given, it sets the specified option flags, or clears
864 them if the option flags are introduced with a
868 Only the first argument to
871 The possible options are:
876 \fB-e\fR Causes the shell to exit when a command terminates with
877 a nonzero exit status, except when the exit status of the command is
878 explicitly tested. The exit status of a command is considered to be
879 explicitly tested if the command is used to control an
885 or if the command is the left hand operand of an ``&&'' or ``||''
889 \fB-f\fR Turn off file name generation.
892 \fB-I\fR Cause the shell to ignore end of file conditions.
893 (This doesn't apply when the shell a script sourced using the ``.''
894 command.) The shell will in fact exit if it gets 50 eof's in a
898 \fB-i\fR Make the shell interactive. This causes the shell to
899 prompt for input, to trap interrupts, to ignore quit and terminate signals,
900 and to return to the main command loop rather than exiting on error.
903 \fB-j\fR Turns on Berkeley job control, on systems that support it.
904 When the shell starts up, the
906 is set by default if the
911 \fB-n\fR Causes the shell to read commands but not execute them.
912 (This is marginally useful for checking the syntax of scripts.)
915 \fB-s\fR If this flag is set when the shell starts up, the shell
916 reads commands from its standard input. The shell doesn't examine the
917 value of this flag any other time.
920 \fB-x\fR If this flag is set, the shell will print out each
921 command before executing it.
924 \fB-z\fR If this flag is set, the file name generation process
925 may generate zero files. If it is not set, then a pattern which does
926 not match any files will be replaced by a quoted version of the pattern.
929 The third use of the set command is to set the values of the shell's
930 positional parameters to the specified
932 To change the positional parameters without changing any options,
933 use ``\fB--\fR'' as the first argument to
935 If no args are present, the set command will leave the value of the
936 positional parameters unchanged, so to set the positional parameters
937 to set of values that may be empty, execute the command
941 first to clear out the old values of the positional parameters.
950 (In general it is better to write
955 is intended to be used in functions that assign values to variables whose
956 names are passed as parameters.)
962 Shift the positional parameters
965 A shift sets the value of $1 to the value of $2, the value of $2 to
966 the value of $3, and so on, decreasing the value of $# by one.
967 If there are zero positional parameters, shifting doesn't do anything.
974 Cause the shell to parse and execute
976 when any of the specified signals are received.
977 The signals are specified by signal number.
979 may be null or omitted;
980 the former causes the specified signal to be ignored and the latter
981 causes the default action to be taken.
982 When the shell forks off a subshell, it resets trapped (but not ignored)
983 signals to the default action.
984 The trap command has no effect on signals that were ignored on entry
991 Set the value of umask (see
993 to the specified octal value. If the argument is omitted, the umask
998 The specified variables and functions are unset and unexported.
999 If a given name corresponds to both a variable and a function, both the
1000 variable and the function are unset.
1006 Wait for the specified job to complete and return the exit status of the
1007 last process in the job. If the argument is omitted, wait for all jobs
1008 to complete and the return an exit status of zero.
1010 The following function redefines the \fIcd\fR command:
1014 then if test -f .enter
1021 This function causes the file ``.enter'' to be read when you enter a
1022 directory, if it exists. The \fIcommand\fR command is used to access the
1023 real \fIcd\fR command. The ``return 0'' ensures that the function will
1024 return an exit status of zero if it successfully changes to a directory
1025 that does not contain a ``.enter'' file. Redefining existing commands
1026 is not always a good idea, but this example shows that you can do it if
1029 The suspend function distributed with
1033 # Copyright (C) 1989 by Kenneth Almquist. All rights reserved.
1034 # This file is part of ash, which is distributed under the terms
1035 # specified by the Ash General Public License.
1043 This turns off job control and then sends a stop signal to the current
1044 process group, which suspends the shell. (When job control is turned
1045 on, the shell ignores the TSTP signal.) Job control will be turned back
1046 on when the function returns because ``-'' is local to the function.
1047 As an example of what \fInot\fR to do, consider an earlier version of
1057 There are two problems with this. First, \fBsuspend_flag\fR is a global
1058 variable rather than a local one, which will cause problems in the
1059 (unlikely) circumstance that the user is using that variable for some
1060 other purpose. Second, consider what happens if shell received an interrupt
1061 signal after it executes the first \fIset\fR command but before it executes
1062 the second one. The interrupt signal will abort the shell function, so
1063 that the second \fIset\fR command will never be executed and job control
1064 will be left off. The first version of \fIsuspend\fR avoids this problem
1065 by turning job control off only in a local copy of the shell options. The
1066 local copy of the shell options is discarded when the function is terminated,
1067 no matter how it is terminated.
1069 Shell variables can be used to provide abbreviations for things which
1070 you type frequently. For example, I set
1072 .\" \h'1i'export h=$HOME
1073 .\" Cawf can't do \h'1i'
1078 in my .profile so that I can type the name of my home directory simply
1081 When writing shell procedures, try not to make assumptions about what is
1082 imported from the environment. Explicitly unset or initialize all variables,
1083 rather than assuming they will be unset. If you use cd, it is a good idea
1086 People sometimes use ``<&-'' or ``>&-'' to provide no input to a command
1087 or to discard the output of a command. A better way to do this is
1088 to redirect the input or output of the command to
1091 Word splitting and file name generation are performed by default,
1092 and you have to explicitly use double quotes to suppress it. This is
1093 backwards, but you can learn to live with it. Just get in the habit of
1094 writing double quotes around variable and command substitutions, and
1095 omit them only when you really want word splitting and file name generation.
1096 If you want word splitting but not file name generation, use the
1102 echo(1), expr(1), line(1), pwd(1), true(1).
1104 When command substitution occurs inside a here document, the commands inside
1105 the here document are run with their standard input closed. For example,
1106 the following will not work because the standard input of the
1108 command will be closed when the command is run:
1116 Unsetting a function which is currently being executed may cause strange
1119 The shell syntax allows a here document to be terminated by an end of file
1120 as well as by a line containing the terminator word which follows the ``<<''.
1121 What this means is that if you mistype the terminator line, the shell
1122 will silently swallow up the rest of your shell script and stick it
1123 in the here document.
1124 .\" several minor typos corrected -- ASW 2005-01-15