blob: 2478f1630ce235a116f62cfebe1559a146d629f8 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001This file is reserved.def, in which the shell reserved words are defined.
2It has no direct C file production, but defines builtins for the Bash
3builtin help command.
4
Jari Aalto31859422009-01-12 13:36:28 +00005Copyright (C) 1987-2009 Free Software Foundation, Inc.
Jari Aalto726f6381996-08-26 18:22:31 +00006
7This file is part of GNU Bash, the Bourne Again SHell.
8
Jari Aalto31859422009-01-12 13:36:28 +00009Bash is free software: you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation, either version 3 of the License, or
12(at your option) any later version.
Jari Aalto726f6381996-08-26 18:22:31 +000013
Jari Aalto31859422009-01-12 13:36:28 +000014Bash is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
Jari Aalto726f6381996-08-26 18:22:31 +000018
Jari Aalto31859422009-01-12 13:36:28 +000019You should have received a copy of the GNU General Public License
20along with Bash. If not, see <http://www.gnu.org/licenses/>.
Jari Aalto726f6381996-08-26 18:22:31 +000021
22$BUILTIN for
Jari Aalto31859422009-01-12 13:36:28 +000023$SHORT_DOC for NAME [in WORDS ... ] ; do COMMANDS; done
24Execute commands for each member in a list.
25
Jari Aalto726f6381996-08-26 18:22:31 +000026The `for' loop executes a sequence of commands for each member in a
27list of items. If `in WORDS ...;' is not present, then `in "$@"' is
28assumed. For each element in WORDS, NAME is set to that element, and
29the COMMANDS are executed.
Jari Aalto31859422009-01-12 13:36:28 +000030
31Exit Status:
32Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +000033$END
34
Jari Aalto7117c2d2002-07-17 14:10:11 +000035$BUILTIN for ((
36$DOCNAME arith_for
37$SHORT_DOC for (( exp1; exp2; exp3 )); do COMMANDS; done
Jari Aalto31859422009-01-12 13:36:28 +000038Arithmetic for loop.
39
Jari Aalto7117c2d2002-07-17 14:10:11 +000040Equivalent to
41 (( EXP1 ))
42 while (( EXP2 )); do
43 COMMANDS
44 (( EXP3 ))
45 done
46EXP1, EXP2, and EXP3 are arithmetic expressions. If any expression is
47omitted, it behaves as if it evaluates to 1.
Jari Aalto31859422009-01-12 13:36:28 +000048
49Exit Status:
50Returns the status of the last command executed.
Jari Aalto7117c2d2002-07-17 14:10:11 +000051$END
52
Jari Aalto726f6381996-08-26 18:22:31 +000053$BUILTIN select
54$SHORT_DOC select NAME [in WORDS ... ;] do COMMANDS; done
Jari Aalto31859422009-01-12 13:36:28 +000055Select words from a list and execute commands.
56
Jari Aalto726f6381996-08-26 18:22:31 +000057The WORDS are expanded, generating a list of words. The
58set of expanded words is printed on the standard error, each
59preceded by a number. If `in WORDS' is not present, `in "$@"'
60is assumed. The PS3 prompt is then displayed and a line read
61from the standard input. If the line consists of the number
62corresponding to one of the displayed words, then NAME is set
63to that word. If the line is empty, WORDS and the prompt are
64redisplayed. If EOF is read, the command completes. Any other
65value read causes NAME to be set to null. The line read is saved
66in the variable REPLY. COMMANDS are executed after each selection
Jari Aalto7117c2d2002-07-17 14:10:11 +000067until a break command is executed.
Jari Aalto31859422009-01-12 13:36:28 +000068
69Exit Status:
70Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +000071$END
72
Jari Aaltoccc6cda1996-12-23 17:02:34 +000073$BUILTIN time
Jari Aalto31859422009-01-12 13:36:28 +000074$SHORT_DOC time [-p] pipeline
75Report time consumed by pipeline's execution.
76
Jari Aaltoccc6cda1996-12-23 17:02:34 +000077Execute PIPELINE and print a summary of the real time, user CPU time,
78and system CPU time spent executing PIPELINE when it terminates.
Jari Aalto31859422009-01-12 13:36:28 +000079
80Options:
81 -p print the timing summary in the portable Posix format
82
83The value of the TIMEFORMAT variable is used as the output format.
84
85Exit Status:
86The return status is the return status of PIPELINE.
Jari Aaltoccc6cda1996-12-23 17:02:34 +000087$END
88
Jari Aalto726f6381996-08-26 18:22:31 +000089$BUILTIN case
90$SHORT_DOC case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac
Jari Aalto31859422009-01-12 13:36:28 +000091Execute commands based on pattern matching.
92
Jari Aalto726f6381996-08-26 18:22:31 +000093Selectively execute COMMANDS based upon WORD matching PATTERN. The
94`|' is used to separate multiple patterns.
Jari Aalto31859422009-01-12 13:36:28 +000095
96Exit Status:
97Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +000098$END
99
100$BUILTIN if
101$SHORT_DOC if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
Jari Aalto31859422009-01-12 13:36:28 +0000102Execute commands based on conditional.
103
Jari Aalto95732b42005-12-07 14:08:12 +0000104The `if COMMANDS' list is executed. If its exit status is zero, then the
105`then COMMANDS' list is executed. Otherwise, each `elif COMMANDS' list is
106executed in turn, and if its exit status is zero, the corresponding
107`then COMMANDS' list is executed and the if command completes. Otherwise,
108the `else COMMANDS' list is executed, if present. The exit status of the
109entire construct is the exit status of the last command executed, or zero
110if no condition tested true.
Jari Aalto31859422009-01-12 13:36:28 +0000111
112Exit Status:
113Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +0000114$END
115
116$BUILTIN while
117$SHORT_DOC while COMMANDS; do COMMANDS; done
Jari Aalto31859422009-01-12 13:36:28 +0000118Execute commands as long as a test succeeds.
119
Jari Aalto726f6381996-08-26 18:22:31 +0000120Expand and execute COMMANDS as long as the final command in the
121`while' COMMANDS has an exit status of zero.
Jari Aalto31859422009-01-12 13:36:28 +0000122
123Exit Status:
124Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +0000125$END
126
127$BUILTIN until
128$SHORT_DOC until COMMANDS; do COMMANDS; done
Jari Aalto31859422009-01-12 13:36:28 +0000129Execute commands as long as a test does not succeed.
130
Jari Aalto726f6381996-08-26 18:22:31 +0000131Expand and execute COMMANDS as long as the final command in the
132`until' COMMANDS has an exit status which is not zero.
Jari Aalto31859422009-01-12 13:36:28 +0000133
134Exit Status:
135Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +0000136$END
137
Jari Aalto17345e52009-02-19 22:21:29 +0000138$BUILTIN coproc
139$SHORT_DOC coproc [NAME] command [redirections]
140Create a coprocess named NAME.
141
142Execute COMMAND asynchronously, with the standard output and standard
143input of the command connected via a pipe to file descriptors assigned
144to indices 0 and 1 of an array variable NAME in the executing shell.
145The default NAME is "COPROC".
146
147Exit Status:
148Returns the exit status of COMMAND.
149$END
150
Jari Aalto726f6381996-08-26 18:22:31 +0000151$BUILTIN function
Jari Aalto31859422009-01-12 13:36:28 +0000152$SHORT_DOC function name { COMMANDS ; } or name () { COMMANDS ; }
153Define shell function.
154
155Create a shell function named NAME. When invoked as a simple command,
156NAME runs COMMANDs in the calling shell's context. When NAME is invoked,
157the arguments are passed to the function as $1...$n, and the function's
158name is in $FUNCNAME.
159
160Exit Status:
161Returns success unless NAME is readonly.
Jari Aalto726f6381996-08-26 18:22:31 +0000162$END
163
164$BUILTIN { ... }
165$DOCNAME grouping_braces
Jari Aaltob72432f1999-02-19 17:11:39 +0000166$SHORT_DOC { COMMANDS ; }
Jari Aalto31859422009-01-12 13:36:28 +0000167Group commands as a unit.
168
Jari Aalto726f6381996-08-26 18:22:31 +0000169Run a set of commands in a group. This is one way to redirect an
170entire set of commands.
Jari Aalto31859422009-01-12 13:36:28 +0000171
172Exit Status:
173Returns the status of the last command executed.
Jari Aalto726f6381996-08-26 18:22:31 +0000174$END
175
176$BUILTIN %
177$DOCNAME fg_percent
Jari Aalto31859422009-01-12 13:36:28 +0000178$SHORT_DOC job_spec [&]
179Resume job in foreground.
180
Jari Aalto95732b42005-12-07 14:08:12 +0000181Equivalent to the JOB_SPEC argument to the `fg' command. Resume a
182stopped or background job. JOB_SPEC can specify either a job name
183or a job number. Following JOB_SPEC with a `&' places the job in
184the background, as if the job specification had been supplied as an
185argument to `bg'.
Jari Aalto31859422009-01-12 13:36:28 +0000186
187Exit Status:
188Returns the status of the resumed job.
Jari Aalto726f6381996-08-26 18:22:31 +0000189$END
190
Jari Aalto7117c2d2002-07-17 14:10:11 +0000191$BUILTIN (( ... ))
192$DOCNAME arith
193$SHORT_DOC (( expression ))
Jari Aalto31859422009-01-12 13:36:28 +0000194Evaluate arithmetic expression.
195
Jari Aalto7117c2d2002-07-17 14:10:11 +0000196The EXPRESSION is evaluated according to the rules for arithmetic
197evaluation. Equivalent to "let EXPRESSION".
Jari Aalto31859422009-01-12 13:36:28 +0000198
199Exit Status:
200Returns 1 if EXPRESSION evaluates to 0; returns 0 otherwise.
Jari Aalto7117c2d2002-07-17 14:10:11 +0000201$END
202
203$BUILTIN [[ ... ]]
204$DOCNAME conditional
205$SHORT_DOC [[ expression ]]
Jari Aalto31859422009-01-12 13:36:28 +0000206Execute conditional command.
207
Jari Aalto7117c2d2002-07-17 14:10:11 +0000208Returns a status of 0 or 1 depending on the evaluation of the conditional
209expression EXPRESSION. Expressions are composed of the same primaries used
Jari Aalto31859422009-01-12 13:36:28 +0000210by the `test' builtin, and may be combined using the following operators:
Jari Aalto7117c2d2002-07-17 14:10:11 +0000211
Jari Aalto31859422009-01-12 13:36:28 +0000212 ( EXPRESSION ) Returns the value of EXPRESSION
213 ! EXPRESSION True if EXPRESSION is false; else false
214 EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
215 EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false
Jari Aalto7117c2d2002-07-17 14:10:11 +0000216
Jari Aalto31859422009-01-12 13:36:28 +0000217When the `==' and `!=' operators are used, the string to the right of
218the operator is used as a pattern and pattern matching is performed.
219When the `=~' operator is used, the string to the right of the operator
220is matched as a regular expression.
221
222The && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
Jari Aalto7117c2d2002-07-17 14:10:11 +0000223determine the expression's value.
Jari Aalto31859422009-01-12 13:36:28 +0000224
225Exit Status:
2260 or 1 depending on value of EXPRESSION.
Jari Aalto7117c2d2002-07-17 14:10:11 +0000227$END
228
Jari Aalto726f6381996-08-26 18:22:31 +0000229$BUILTIN variables
230$DOCNAME variable_help
Jari Aalto31859422009-01-12 13:36:28 +0000231$SHORT_DOC variables - Names and meanings of some shell variables
232Common shell variable names and usage.
233
Jari Aalto06285672006-10-10 14:15:34 +0000234BASH_VERSION Version information for this Bash.
235CDPATH A colon-separated list of directories to search
Jari Aalto31859422009-01-12 13:36:28 +0000236 for directories given as arguments to `cd'.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000237GLOBIGNORE A colon-separated list of patterns describing filenames to
238 be ignored by pathname expansion.
Jari Aalto726f6381996-08-26 18:22:31 +0000239#if defined (HISTORY)
Jari Aalto06285672006-10-10 14:15:34 +0000240HISTFILE The name of the file where your command history is stored.
241HISTFILESIZE The maximum number of lines this file can contain.
242HISTSIZE The maximum number of history lines that a running
Jari Aalto726f6381996-08-26 18:22:31 +0000243 shell can access.
244#endif /* HISTORY */
Jari Aalto06285672006-10-10 14:15:34 +0000245HOME The complete pathname to your login directory.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000246HOSTNAME The name of the current host.
Jari Aalto06285672006-10-10 14:15:34 +0000247HOSTTYPE The type of CPU this version of Bash is running under.
248IGNOREEOF Controls the action of the shell on receipt of an EOF
Jari Aalto726f6381996-08-26 18:22:31 +0000249 character as the sole input. If set, then the value
250 of it is the number of EOF characters that can be seen
251 in a row on an empty line before the shell will exit
252 (default 10). When unset, EOF signifies the end of input.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000253MACHTYPE A string describing the current system Bash is running on.
Jari Aalto726f6381996-08-26 18:22:31 +0000254MAILCHECK How often, in seconds, Bash checks for new mail.
255MAILPATH A colon-separated list of filenames which Bash checks
256 for new mail.
Jari Aalto06285672006-10-10 14:15:34 +0000257OSTYPE The version of Unix this version of Bash is running on.
258PATH A colon-separated list of directories to search when
Jari Aalto726f6381996-08-26 18:22:31 +0000259 looking for commands.
Jari Aalto06285672006-10-10 14:15:34 +0000260PROMPT_COMMAND A command to be executed before the printing of each
Jari Aalto726f6381996-08-26 18:22:31 +0000261 primary prompt.
Jari Aalto06285672006-10-10 14:15:34 +0000262PS1 The primary prompt string.
263PS2 The secondary prompt string.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000264PWD The full pathname of the current directory.
265SHELLOPTS A colon-separated list of enabled shell options.
Jari Aalto06285672006-10-10 14:15:34 +0000266TERM The name of the current terminal type.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000267TIMEFORMAT The output format for timing statistics displayed by the
268 `time' reserved word.
Jari Aalto06285672006-10-10 14:15:34 +0000269auto_resume Non-null means a command word appearing on a line by
Jari Aalto726f6381996-08-26 18:22:31 +0000270 itself is first looked for in the list of currently
271 stopped jobs. If found there, that job is foregrounded.
272 A value of `exact' means that the command word must
273 exactly match a command in the list of stopped jobs. A
274 value of `substring' means that the command word must
275 match a substring of the job. Any other value means that
276 the command must be a prefix of a stopped job.
277#if defined (HISTORY)
Jari Aalto726f6381996-08-26 18:22:31 +0000278# if defined (BANG_HISTORY)
Jari Aalto06285672006-10-10 14:15:34 +0000279histchars Characters controlling history expansion and quick
Jari Aalto726f6381996-08-26 18:22:31 +0000280 substitution. The first character is the history
281 substitution character, usually `!'. The second is
282 the `quick substitution' character, usually `^'. The
283 third is the `history comment' character, usually `#'.
284# endif /* BANG_HISTORY */
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000285HISTIGNORE A colon-separated list of patterns used to decide which
Jari Aaltof73dda02001-11-13 17:56:06 +0000286 commands should be saved on the history list.
Jari Aalto726f6381996-08-26 18:22:31 +0000287#endif /* HISTORY */
288$END