source: trunk/minix/man/man1/ash.1@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 36.3 KB
Line 
1.\" Copyright (c) 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Kenneth Almquist.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
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.
22.\"
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
33.\" SUCH DAMAGE.
34.\"
35.\" @(#)sh.1 5.1 (Berkeley) 3/7/91
36.\"
37.TH SH 1 "March 7, 1991"
38.UC 7
39.de h \" subheading
40.sp
41.ti -0.3i
42.B "\\$1"
43.PP
44..
45.de d \" begin display
46.sp
47.in +4
48.nf
49..
50.de e \" end display
51.in -4
52.fi
53.sp
54..
55.de c \" command, etc.
56.br
57.HP 3
58\fB\\$1\fR
59.br
60..
61.de b \" begin builtin command
62.HP 3
63.B \\$1
64..
65.SH NAME
66ash, 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
67.SH SYNOPSIS
68.B ash
69[
70.B -efIijnsxz
71] [
72.B +efIijnsxz
73] [
74.B -c
75.I command
76] [
77.I arg
78] ...
79.SH COPYRIGHT
80Copyright 1989 by Kenneth Almquist.
81.SH DESCRIPTION
82.I Ash
83is a version of
84.I sh
85with features similar to those of the System V shell.
86This manual page lists all the features of
87.I ash
88but concentrates on the ones not in other shells.
89.h "Invocation"
90If the
91.B -c
92options is given, then the shell executes the specified shell command.
93The
94.B -s
95flag cause the shell to read commands from the standard input (after
96executing any command specified with the
97.B -c
98option.
99If neither the
100.B -s
101or
102.B -c
103options are set, then the first
104.I arg
105is taken as the name of a file to read commands from.
106If this is impossible because there are no arguments following
107the options, then
108.I ash
109will set the
110.B -s
111flag and will read commands from the standard input.
112.PP
113The shell sets the initial value of the positional parameters from the
114.IR arg s
115remaining after any
116.I arg
117used as the name of a file of commands is deleted.
118.PP
119The flags (other than
120.BR -c )
121are set by preceding them with ``-'' and cleared by preceding them
122with ``+''; see the
123.I set
124builtin command for a list of flags.
125If no value is specified for the
126.B -i
127flag, the
128.B -s
129flag is set, and the standard input and output of the shell
130are connected to terminals, then the
131.B -i
132flag will be set.
133If no value is specified for the
134.B -j
135flag, then the
136.B -j
137flag will be set if the
138.B -i
139flag is set.
140.PP
141When the shell is invoked with the
142.B -c
143option, it is good practice to include the
144.I -i
145flag if the command was entered interactively by a user.
146For compatibility with the System V shell, the
147.I -i
148option should come after the
149.B -c
150option.
151.PP
152If the first character of argument zero to the shell is ``-'',
153the shell is assumed to be a login shell, and the files
154.B /etc/profile
155and
156.B .profile
157are read if they exist.
158If the environment variable SHINIT is set on entry to the shell,
159the commands in SHINIT are normally parsed and executed. SHINIT is
160not examined if the shell is a login shell, or if it the shell is running a
161shell procedure. (A shell is considered to be running a shell
162procedure if neither the
163.B -s
164nor the
165.B -c
166options are set.)
167.h "Control Structures"
168A
169.I list
170is a sequence of zero or more commands separated by newlines,
171semicolons, or ampersands, and optionally terminated by one of these
172three characters. (This differs from the System V shell, which
173requires a list to contain at least one command in most cases.) The
174commands in a list are executed in the order they are written.
175If command is followed by an ampersand, the shell starts the command
176and immediately proceed onto the next command; otherwise it waits
177for the command to terminate before proceeding to the next one.
178.PP
179``&&'' and ``||'' are binary operators.
180``&&'' executes the first command, and then executes the second command
181iff the exit status of the first command is zero. ``||'' is similar,
182but executes the second command iff the exit status of the first command
183is nonzero. ``&&'' and ``||'' both have the same priority.
184.PP
185The ``|'' operator is a binary operator which feeds the standard output
186of the first command into the standard input of the second command.
187The exit status of the ``|'' operator is the exit status of the second
188command. ``|'' has a higher priority than ``||'' or ``&&''.
189.PP
190An
191.I if
192command looks like
193.d
194\fBif\fR list
195\fBthen\fR list
196.ti -\w'[ 'u
197[ \fBelif\fR list
198 \fBthen\fR list ] ...
199.ti -\w'[ 'u
200[ \fBelse\fR list ]
201\fBfi\fR
202.e
203.PP
204A
205.I while
206command looks like
207.d
208\fBwhile\fR list
209\fBdo\fR list
210\fBdone\fR
211.e
212The two lists are executed repeatedly while the exit status of the first
213list is zero. The
214.I until
215command is similar, but has the word
216.B until
217in place of
218.B while
219 repeats until the exit status of the first list
220is zero.
221.PP
222The
223.I for
224command looks like
225.d
226\fBfor\fR variable \fBin\fR word...
227\fBdo\fR list
228\fBdone\fR
229.e
230The words are expanded, and then the list is executed repeatedly with
231the variable set to each word in turn.
232.B do
233and
234.B done
235may be replaced with
236``{'' and ``}''.
237.PP
238The
239.I break
240and
241.I continue
242commands look like
243.d
244\fBbreak\fR [ num ]
245\fBcontinue\fR [ num ]
246.e
247.I Break
248terminates the
249.I num
250innermost
251.I for
252or
253.I while
254loops.
255.I Continue
256continues with the next iteration of the
257.IRnum'th
258innermost loop.
259These are implemented as builtin commands.
260.PP
261The
262.I case
263command looks like
264.d
265\fBcase\fR word \fBin\fR
266pattern\fB)\fR list \fB;;\fR
267\&...
268\fBesac\fR
269.e
270The pattern can actually be one or more patterns (see
271.I Patterns
272below), separated by ``|'' characters.
273.PP
274Commands may be grouped by writing either
275.d
276\fB(\fRlist\fB)\fR
277.e
278or
279.d
280\fB{\fR list; \fB}\fR
281.e
282The first of these executes the commands in a subshell.
283.PP
284A function definition looks like
285.d
286name \fB( )\fR command
287.e
288A function definition is an executable statement; when executed it installs
289a function named
290.B name
291and returns an exit status of zero.
292The command is normally a list enclosed between ``{'' and ``}''.
293.PP
294Variables may be declared to be local to a function by using a
295.I local
296command. This should appear as the first staement of a function,
297and looks like
298.d
299\fBlocal\fR [ variable | \fB-\fR ] ...
300.e
301.I Local
302is implemented as a builtin command.
303.PP
304When a variable is made local, it inherits the initial value and
305exported and readonly flags from the variable with the same name in the
306surrounding scope, if there is one. Otherwise, the variable is
307initially unset.
308.I Ash
309uses dynamic scoping, so that if you make the variable
310.B x
311local to function
312.IR f ,
313which then calls function
314.IR g ,
315references to the variable
316.B x
317made inside
318.I g
319will refer to the variable
320.B x
321declared inside
322.IR f ,
323not to the global variable named
324.BR x .
325.PP
326The only special parameter that can be made local is ``\fB-\fR''.
327Making ``\fB-\fR'' local any shell options that are changed via the
328.I set
329command inside the function to be restored to their original values
330when the function returns.
331.PP
332The
333.I return
334command looks like
335.d
336\fBreturn\fR [ exitstatus ]
337.e
338It terminates the currently executing function.
339.I Return
340is implemented as a builtin command.
341.h "Simple Commands"
342A simple command is a sequence of words. The execution of a simple
343command proceeds as follows. First, the leading words of the form
344``name=value'' are stripped off and assigned to the environment of
345the command. Second, the words are expanded. Third, the first
346remaining word is taken as the command name that command is located.
347Fourth, any redirections are performed. Fifth, the command is
348executed. We look at these operations in reverse order.
349.PP
350The execution of the command varies with the type of command.
351There are three types of commands: shell functions, builtin commands,
352and normal programs.
353.PP
354When 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
356function. The variables which are explicitly placed in the environment
357of the command (by placing assignments to them before the function name)
358are made local to the function and are set to values given.
359Then the command given in the function definition is executed.
360The positional parameters are restored to their original values when
361the command completes.
362.PP
363Shell builtins are executed internally to the shell, without spawning
364a new process.
365.PP
366When a normal program is executed, the shell runs the program, passing
367the parameters and the environment to the program. If the program is
368a shell procedure, the shell will interpret the program in a subshell.
369The shell will reinitialize itself in this case, so that the effect
370will be as if a new shell had been invoked to handle the shell procedure,
371except that the location of commands located in the parent shell will
372be remembered by the child. If the program is a file beginning with
373``#!'', the remainder of the first line specifies an interpreter for
374the program. The shell (or the operating system, under Berkeley UNIX)
375will run the interpreter in this case. The arguments to the interpreter
376will consist of any arguments given on the first line of the program,
377followed by the name of the program, followed by the arguments passed
378to the program.
379.h "Redirection"
380Input/output redirections can be intermixed with the words in a simple
381command and can be placed following any of the other commands. When
382redirection occurs, the shell saves the old values of the file descriptors
383and restores them when the command completes. The ``<'', ``>'', and ``>>''
384redirections open a file for input, output, and appending, respectively.
385The ``<&digit'' and ``>&digit'' makes the input or output a duplicate
386of the file descriptor numbered by the digit. If a minus sign is used
387in place of a digit, the standard input or standard output are closed.
388.PP
389The ``<<\ word'' redirection
390takes input from a
391.I here
392document.
393As the shell encounters ``<<'' redirections, it collects them. The
394next time it encounters an unescaped newline, it reads the documents
395in turn. The word following the ``<<'' specifies the contents of the
396line that terminates the document. If none of the quoting methods
397('', "", or \e) are used to enter the word, then the document is treated
398like a word inside double quotes: ``$'' and backquote are expanded
399and backslash can be used to escape these and to continue long lines.
400The word cannot contain any variable or command substitutions, and
401its length (after quoting) must be in the range of 1 to 79 characters.
402If ``<<-'' is used in place of ``<<'', then leading tabs are deleted
403from the lines of the document. (This is to allow you do indent shell
404procedures containing here documents in a natural fashion.)
405.PP
406Any of the preceding redirection operators may be preceded by a single
407digit specifying the file descriptor to be redirected. There cannot
408be any white space between the digit and the redirection operator.
409.h "Path Search"
410When locating a command, the shell first looks to see if it has a
411shell function by that name. Then, if PATH does not contain an
412entry for "%builtin", it looks for a builtin command by that name.
413Finally, it searches each entry in PATH in turn for the command.
414.PP
415The value of the PATH variable should be a series of entries separated
416by colons.
417Each entry consists of a directory name, or a directory name followed
418by a flag beginning with a percent sign.
419The current directory should be indicated by an empty directory name.
420.PP
421If no percent sign is present, then the entry causes the shell to
422search for the command in the specified directory. If the flag is
423``%builtin'' then the list of shell builtin commands is searched.
424If the flag is ``%func'' then the directory is searched for a file which
425is read as input to the shell. This file should define a function
426whose name is the name of the command being searched for.
427.PP
428Command names containing a slash are simply executed without performing
429any of the above searches.
430.h "The Environment"
431The environment of a command is a set of name/value pairs. When the
432shell is invoked, it reads these names and values, sets the shell
433variables with these names to the corresponding values, and marks
434the variables as exported. The
435.I export
436command can be used to mark additional variables as exported.
437.PP
438The environment of a command is constructed by constructing name/value
439pairs from all the exported shell variables, and then modifying this
440set by the assignments which precede the command, if any.
441.h "Expansion"
442The process of evaluating words when a shell procedure is executed is
443called
444.IR expansion .
445Expansion consists of four steps: variable substitution, command
446substitution, word splitting, and file name generation. If a word
447is the expression following the word
448.B case
449in a case statement, the file name
450which follows a redirection symbol, or an assignment to the environment
451of a command, then the word cannot be split into multiple words. In
452these cases, the last two steps of the expansion process are omitted.
453.h "Variable Substitution"
454To be written.
455.h "Command Substitution"
456.I Ash
457accepts two syntaxes for command substitution:
458.d
459`\fIlist\fR`
460.e
461and
462.d
463$(\fIlist\fR)
464.e
465Either of these may be included in a word.
466During the command substitution process, the command (syntactly a
467.IR list )
468will be executed and anything that the command writes to the standard
469output will be captured by the shell. The final newline (if any) of
470the output will be deleted; the rest of the output will be substituted
471for the command in the word.
472.h "Word Splitting"
473When the value of a variable or the output of a command is substituted,
474the resulting text is subject to word splitting, unless the dollar sign
475introducing the variable or backquotes containing the text were enclosed
476in double quotes. In addition, ``$@'' is subject to a special type of
477splitting, even in the presence of double quotes.
478.PP
479Ash uses two different splitting algorithms. The normal approach, which
480is intended for splitting text separated by which space, is used if the
481first character of the shell variable IFS is a space. Otherwise an alternative
482experimental algorithm, which is useful for splitting (possibly empty)
483fields separated by a separator character, is used.
484.PP
485When performing splitting, the shell scans the replacement text looking
486for a character (when IFS does not begin with a space) or a sequence of
487characters (when IFS does begin with a space), deletes the character or
488sequence of characters, and spits the word into two strings at that
489point. When IFS begins with a space, the shell deletes either of the
490strings if they are null. As a special case, if the word containing
491the replacement text is the null string, the word is deleted.
492.PP
493The variable ``$@'' is special in two ways. First, splitting takes
494place between the positional parameters, even if the text is enclosed
495in double quotes. Second, if the word containing the replacement
496text is the null string and there are no positional parameters, then
497the word is deleted. The result of these rules is that "$@" is
498equivalent to "$1" "$2" ... "$\fIn\fR", where \fIn\fR is the number of
499positional parameters. (Note that this differs from the System V shell.
500The System V documentation claims that "$@" behaves this way; in fact
501on the System V shell "$@" is equivalent to "" when there are no
502positional paramteters.)
503.h "File Name Generation"
504Unless the
505.B -f
506flag is set, file name generation is performed after word splitting is
507complete. Each word is viewed as a series of patterns, separated by
508slashes. The process of expansion replaces the word with the names of
509all existing files whose names can be formed by replacing each pattern
510with a string that matches the specified pattern. There are two
511restrictions on this: first, a pattern cannot match a string containing
512a slash, and second, a pattern cannot match a string starting with a
513period unless the first character of the pattern is a period.
514.PP
515If a word fails to match any files and the
516.B -z
517flag is not set, then the word will be left unchanged (except that the
518meta-characters will be converted to normal characters). If the
519.B -z
520flag is set, then the word is only left unchanged if none
521of the patterns contain a character that can match anything besides
522itself. Otherwise the
523.B -z
524flag forces the word to be replaced with the names of the files that it
525matches, even if there are zero names.
526.h "Patterns"
527A
528.I pattern
529consists of normal characters, which match themselves, and meta-characters.
530The meta-characters are ``!'', ``*'', ``?'', and ``[''. These characters lose
531there special meanings if they are quoted. When command or variable
532substitution is performed and the dollar sign or back quotes are not
533double quoted, the value of the variable or the output of the command
534is scanned for these characters and they are turned into meta-characters.
535.PP
536Two exclamation points at the beginning of a pattern function as a ``not''
537operator, causing the pattern to match any string that the remainder of
538the pattern does
539.I not
540match. Other occurances of exclamation points in a pattern match
541exclamation points. Two exclamation points are required rather than one
542to decrease the incompatibility with the System V shell (which does not
543treat exclamation points specially).
544.PP
545An asterisk (``*'') matches any string of characters.
546A question mark matches any single character.
547A left bracket (``['') introduces a character class. The end of the
548character class is indicated by a ``]''; if the ``]'' is missing then
549the ``['' matches a ``['' rather than introducing a character class.
550A character class matches any of the characters between the square
551brackets. A range of characters may be specified using a minus sign.
552The character class may be complemented by making an exclamation point
553the first character of the character class.
554.PP
555To include a ``]'' in a character class, make it the first character listed
556(after the ``!'', if any).
557To include a minus sign, make it the first or last character listed.
558.h "The /u Directory"
559By convention, the name ``/u/user'' refers to the home directory of the
560specified user. There are good reasons why this feature should be supported
561by the file system (using a feature such as symbolic links) rather than
562by the shell, but
563.I ash
564is capable of performing this mapping if the file system doesn't.
565If the mapping is done by
566.IR ash ,
567setting the
568.B -f
569flag will turn it off.
570.h "Character Set"
571.I Ash
572silently discards nul characters. Any other character will be handled
573correctly by
574.IR ash ,
575including characters with the high order bit set.
576.h "Job Names and Job Control"
577The term
578.I job
579refers to a process created by a shell command, or in the case of a
580pipeline, to the set of processes in the pipeline. The ways to refer
581to a job are:
582.d
583%\fInumber\fR
584%\fIstring\fR
585%%
586\fIprocess_id\fR
587.e
588The first form identifies a job by job number.
589When a command is run,
590.I ash
591assigns it a job number
592(the lowest unused number is assigned).
593The second form identifies a job by giving a prefix of the command used
594to create the job. The prefix must be unique. If there is only one job,
595then the null prefix will identify the job, so you can refer to the job
596by writing ``%''. The third form refers to the \fIcurrent job\fR. The
597current 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
599process id of the last process in the job.
600.PP
601If the operating system that
602.I ash
603is running on supports job control,
604.I ash
605will allow you to use it.
606In this case, typing the suspend character (typically ^Z) while running
607a command will return you to
608.I ash
609and will make the suspended command the current job. You can then continue
610the job in the background by typing
611.IR bg ,
612or you can continue it in the foreground by typing
613.IR fg .
614.h "Atty"
615If the shell variable ATTY is set, and the shell variable TERM is not
616set to ``emacs'', then \fIash\fR generates appropriate escape sequences
617to talk to
618.IR atty (1).
619.h "Exit Statuses"
620By tradition, an exit status of zero means that a command has succeeded
621and a nonzero exit status indicates that the command failed. This is
622better than no convention at all, but in practice it is extremely useful
623to allow commands that succeed to use the exit status to return information
624to the caller. A variety of better conventions have been proposed, but
625none 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
627as follows:
628.ta 1i 2i
629.nf
630 0 Success.
631 1 Alternate success.
632 2 Failure.
633 129-... Command terminated by a signal.
634.fi
635The \fIalternate success\fR return is used by commands to indicate various
636conditions which are not errors but which can, with a little imagination,
637be conceived of as less successful than plain success. For example,
638.I test
639returns 1 when the tested condition is false and
640.I getopts
641returns 1 when there are no more options.
642Because this convention is not used universally, the
643.B -e
644option of
645.I ash
646causes the shell to exit when a command returns 1 even though that
647contradicts the convention described here.
648.PP
649When a command is terminated by a signal, the uses 128 plus the signal
650number as the exit code for the command.
651.h "Builtin Commands"
652This concluding section lists the builtin commands which are builtin
653because they need to perform some operation that can't be performed by a
654separate process. In addition to these, there are several other commands
655.RI ( catf ,
656.IR echo ,
657.IR expr ,
658.IR line ,
659.IR nlecho ,
660.IR test ,
661.RI `` : '',
662and
663.IR true )
664which can optionally be compiled into the shell. The builtin
665commands described below that accept options use the System V Release 2
666.IR getopt (3)
667syntax.
668.sp
669.b bg
670[
671.I job
672] ...
673.br
674Continue the specified jobs (or the current job if no jobs are given)
675in the background.
676This command is only available on systems with Bekeley job control.
677.b command
678.IR "command arg" ...
679.br
680Execute the specified builtin command. (This is useful when you have a
681shell function with the same name as a builtin command.)
682.b cd
683[
684.I directory
685]
686.br
687Switch to the specified directory (default $HOME).
688If the an entry for CDPATH appears in the environment of the cd command
689or the shell variable CDPATH is set and the directory name does not
690begin with a slash, then the directories listed in CDPATH will be
691searched for the specified directory. The format of CDPATH is the
692same as that of PATH.
693In an interactive shell, the cd command will print out the name of the
694directory that it actually switched to if this is different from the
695name that the user gave. These may be different either because
696the 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'
699.b .
700.I file
701.br
702The commands in the specified file are read and executed by the shell.
703A path search is not done to find the file because the directories in
704PATH generally contain files that are intended to be executed, not read.
705.b eval
706.IR string ...
707.br
708The 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.)
711.b exec
712[
713.IR "command arg" ...
714]
715.br
716Unless
717.I command
718is omitted,
719the shell process is replaced with the specified program (which must be a real
720program, not a shell builtin or function).
721Any redirections on the exec command are marked as permanent, so that they
722are not undone when the exec command finishes.
723If the command is not found, the exec command causes the shell to exit.
724.b exit
725[
726.I exitstatus
727]
728.br
729Terminate the shell process. If
730.I exitstatus
731is given it is used as the
732exit status of the shell; otherwise the exit status of the preceding
733command is used.
734.b export
735.IR name ...
736.br
737The specified names are exported so that they will appear in the environment
738of subsequent commands. The only way to un-export a variable is to unset it.
739.I Ash
740allows the value of a variable to be set at the same time it is exported
741by writing
742.d
743\fBexport\fR name=value
744.e
745With no arguments the export command lists the names of all exported variables.
746.b fg
747[
748.I job
749]
750.br
751Move the specified job or the current job to the foreground.
752This command is only available on systems with Bekeley job control.
753.b getopts
754.I optstring
755.I var
756.br
757The System V
758.I getopts
759command.
760.b hash
761.B -rv
762.IR command ...
763.br
764The shell maintains a hash table which remembers the locations of
765commands. With no arguments whatsoever, the hash command prints
766out the contents of this table. Entries which have not been looked
767at since the last
768.I cd
769command are marked with an asterisk; it is possible for these entries
770to be invalid.
771.sp
772With arguments, the hash command removes the specified commands from
773the hash table (unless they are functions) and then locates them.
774With the
775.B -v
776option,
777.I hash
778prints the locations of the commands as it finds them.
779The
780.B -r
781option causes the
782.I hash
783command to delete all the entries in the hash table except for
784functions.
785.b jobid
786[
787.I job
788]
789.br
790Print the process id's of the processes in the job. If the job argument
791is omitted, use the current job.
792.b jobs
793.br
794This command lists out all the background processes which are children
795of the current shell process.
796.b pwd
797.br
798Print the current directory. The builtin command may differ from the
799program of the same name because the builtin command remembers what
800the current directory is rather than recomputing it each time. This
801makes it faster. However, if the current directory is renamed, the
802builtin version of pwd will continue to print the old name for the
803directory.
804.b read
805[
806.B -p
807.I prompt
808]
809[
810.B -e
811]
812.IR variable ...
813.br
814The prompt is printed if the
815.B -p
816option is specified and the standard input is a terminal. Then a
817line is read from the standard input. The trailing newline is deleted
818from the line and the line is split as described
819in the section on word splitting above, and the pieces are assigned to
820the variables in order. If there are more pieces than variables, the
821remaining pieces (along with the characters in IFS that separated them)
822are assigned to the last variable. If there are more variables than
823pieces, the remaining variables are assigned the null string.
824.sp
825The
826.B -e
827option causes any backslashes in the input to be treated specially.
828If a backslash is followed by a newline, the backslash and the newline
829will be deleted. If a backslash is followed by any other character,
830the backslash will be deleted and the following character will be treated
831as though it were not in IFS, even if it is.
832.b readonly
833.IR name ...
834.br
835The specified names are marked as read only, so that they cannot be
836subsequently modified or unset.
837.I Ash
838allows the value of a variable to be set at the same time it is marked
839read only by writing
840.d
841\fBreadonly\fR name=value
842.e
843With no arguments the readonly command lists the names of all
844read only variables.
845.b set
846[
847{
848.BI - options
849|
850.BI + options
851|
852.B --
853}
854]
855.IR arg ...
856.br
857The
858.I set
859command performs three different functions.
860.sp
861With no arguments, it lists the values of all shell variables.
862.sp
863If options are given, it sets the specified option flags, or clears
864them if the option flags are introduced with a
865.B +
866rather than a
867.BR - .
868Only the first argument to
869.I set
870can contain options.
871The possible options are:
872.sp
873.ta 0.4i
874.in +0.4i
875.ti -0.4i
876\fB-e\fR Causes the shell to exit when a command terminates with
877a nonzero exit status, except when the exit status of the command is
878explicitly tested. The exit status of a command is considered to be
879explicitly tested if the command is used to control an
880.IR if ,
881.IR elif ,
882.IR while ,
883or
884.IR until ;
885or if the command is the left hand operand of an ``&&'' or ``||''
886operator.
887.sp
888.ti -0.4i
889\fB-f\fR Turn off file name generation.
890.sp
891.ti -0.4i
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 ``.''
894command.) The shell will in fact exit if it gets 50 eof's in a
895row.
896.sp
897.ti -0.4i
898\fB-i\fR Make the shell interactive. This causes the shell to
899prompt for input, to trap interrupts, to ignore quit and terminate signals,
900and to return to the main command loop rather than exiting on error.
901.sp
902.ti -0.4i
903\fB-j\fR Turns on Berkeley job control, on systems that support it.
904When the shell starts up, the
905.B -j
906is set by default if the
907.B -i
908flag is set.
909.sp
910.ti -0.4i
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.)
913.sp
914.ti -0.4i
915\fB-s\fR If this flag is set when the shell starts up, the shell
916reads commands from its standard input. The shell doesn't examine the
917value of this flag any other time.
918.sp
919.ti -0.4i
920\fB-x\fR If this flag is set, the shell will print out each
921command before executing it.
922.sp
923.ti -0.4i
924\fB-z\fR If this flag is set, the file name generation process
925may generate zero files. If it is not set, then a pattern which does
926not match any files will be replaced by a quoted version of the pattern.
927.in -0.4i
928.sp
929The third use of the set command is to set the values of the shell's
930positional parameters to the specified
931.IR args .
932To change the positional parameters without changing any options,
933use ``\fB--\fR'' as the first argument to
934.IR set .
935If no args are present, the set command will leave the value of the
936positional parameters unchanged, so to set the positional parameters
937to set of values that may be empty, execute the command
938.d
939shift $#
940.e
941first to clear out the old values of the positional parameters.
942.b setvar
943.I variable
944.I value
945.br
946Assigns
947.I value
948to
949.IR variable .
950(In general it is better to write
951.I variable=value
952rather than using
953.IR setvar .
954.I Setvar
955is intended to be used in functions that assign values to variables whose
956names are passed as parameters.)
957.b shift
958[
959.I n
960]
961.br
962Shift the positional parameters
963.I n
964times.
965A shift sets the value of $1 to the value of $2, the value of $2 to
966the value of $3, and so on, decreasing the value of $# by one.
967If there are zero positional parameters, shifting doesn't do anything.
968.b trap
969[
970.I action
971]
972.IR signal ...
973.br
974Cause the shell to parse and execute
975.I action
976when any of the specified signals are received.
977The signals are specified by signal number.
978.I Action
979may be null or omitted;
980the former causes the specified signal to be ignored and the latter
981causes the default action to be taken.
982When the shell forks off a subshell, it resets trapped (but not ignored)
983signals to the default action.
984The trap command has no effect on signals that were ignored on entry
985to the shell.
986.b umask
987[
988.I mask
989]
990.br
991Set the value of umask (see
992.IR umask (2))
993to the specified octal value. If the argument is omitted, the umask
994value is printed.
995.b unset
996.IR name ...
997.br
998The specified variables and functions are unset and unexported.
999If a given name corresponds to both a variable and a function, both the
1000variable and the function are unset.
1001.b wait
1002[
1003.I job
1004]
1005.br
1006Wait for the specified job to complete and return the exit status of the
1007last process in the job. If the argument is omitted, wait for all jobs
1008to complete and the return an exit status of zero.
1009.SH EXAMPLES
1010The following function redefines the \fIcd\fR command:
1011.d
1012cd() {
1013 if command cd "$@"
1014 then if test -f .enter
1015 then . .enter
1016 else return 0
1017 fi
1018 fi
1019}
1020.e
1021This function causes the file ``.enter'' to be read when you enter a
1022directory, if it exists. The \fIcommand\fR command is used to access the
1023real \fIcd\fR command. The ``return 0'' ensures that the function will
1024return an exit status of zero if it successfully changes to a directory
1025that does not contain a ``.enter'' file. Redefining existing commands
1026is not always a good idea, but this example shows that you can do it if
1027you want to.
1028.PP
1029The suspend function distributed with
1030.I ash
1031looks like
1032.d
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.
1036
1037suspend() {
1038 local -
1039 set +j
1040 kill -TSTP 0
1041}
1042.e
1043This turns off job control and then sends a stop signal to the current
1044process group, which suspends the shell. (When job control is turned
1045on, the shell ignores the TSTP signal.) Job control will be turned back
1046on when the function returns because ``-'' is local to the function.
1047As an example of what \fInot\fR to do, consider an earlier version of
1048\fIsuspend\fR:
1049.d
1050suspend() {
1051 suspend_flag=$-
1052 set +j
1053 kill -TSTP 0
1054 set -$suspend_flag
1055}
1056.e
1057There are two problems with this. First, \fBsuspend_flag\fR is a global
1058variable rather than a local one, which will cause problems in the
1059(unlikely) circumstance that the user is using that variable for some
1060other purpose. Second, consider what happens if shell received an interrupt
1061signal after it executes the first \fIset\fR command but before it executes
1062the second one. The interrupt signal will abort the shell function, so
1063that the second \fIset\fR command will never be executed and job control
1064will be left off. The first version of \fIsuspend\fR avoids this problem
1065by turning job control off only in a local copy of the shell options. The
1066local copy of the shell options is discarded when the function is terminated,
1067no matter how it is terminated.
1068.SH HINTS
1069Shell variables can be used to provide abbreviations for things which
1070you type frequently. For example, I set
1071.br
1072.\" \h'1i'export h=$HOME
1073.\" Cawf can't do \h'1i'
1074.in +1i
1075export h=$HOME
1076.in -1i
1077.br
1078in my .profile so that I can type the name of my home directory simply
1079by typing ``$h''.
1080.PP
1081When writing shell procedures, try not to make assumptions about what is
1082imported from the environment. Explicitly unset or initialize all variables,
1083rather than assuming they will be unset. If you use cd, it is a good idea
1084to unset CDPATH.
1085.PP
1086People sometimes use ``<&-'' or ``>&-'' to provide no input to a command
1087or to discard the output of a command. A better way to do this is
1088to redirect the input or output of the command to
1089.BR /dev/null .
1090.PP
1091Word splitting and file name generation are performed by default,
1092and you have to explicitly use double quotes to suppress it. This is
1093backwards, but you can learn to live with it. Just get in the habit of
1094writing double quotes around variable and command substitutions, and
1095omit them only when you really want word splitting and file name generation.
1096If you want word splitting but not file name generation, use the
1097.B -f
1098option.
1099.SH AUTHORS
1100Kenneth Almquist
1101.SH "SEE ALSO"
1102echo(1), expr(1), line(1), pwd(1), true(1).
1103.SH BUGS
1104When command substitution occurs inside a here document, the commands inside
1105the here document are run with their standard input closed. For example,
1106the following will not work because the standard input of the
1107.I line
1108command will be closed when the command is run:
1109.d
1110cat <<-!
1111Line 1: $(line)
1112Line 2: $(line)
1113!
1114.e
1115.PP
1116Unsetting a function which is currently being executed may cause strange
1117behavior.
1118.PP
1119The shell syntax allows a here document to be terminated by an end of file
1120as well as by a line containing the terminator word which follows the ``<<''.
1121What this means is that if you mistype the terminator line, the shell
1122will silently swallow up the rest of your shell script and stick it
1123in the here document.
1124.\" several minor typos corrected -- ASW 2005-01-15
Note: See TracBrowser for help on using the repository browser.