]>
Commit | Line | Data |
---|---|---|
726f6388 JA |
1 | \input texinfo.tex @c -*- texinfo -*- |
2 | @c %**start of header | |
3 | @setfilename features.info | |
4 | @settitle Bash Features | |
5 | @c %**end of header | |
6 | ||
7 | @ignore | |
8 | last change: Thu Aug 4 15:21:56 EDT 1994 | |
9 | @end ignore | |
10 | ||
11 | @set EDITION 1.14 | |
12 | @set VERSION 1.14 | |
13 | @set UPDATED 4 August 1994 | |
14 | @set UPDATE-MONTH August 1994 | |
15 | ||
16 | @setchapternewpage odd | |
17 | @synindex fn cp | |
18 | @set BashFeatures | |
19 | @ifinfo | |
20 | @format | |
21 | This text is a brief description of the features that are present in | |
22 | the Bash shell. | |
23 | ||
24 | This is Edition @value{EDITION}, last updated @value{UPDATED}, | |
25 | of @cite{The GNU Bash Features Guide}, | |
26 | for @code{Bash}, Version @value{VERSION}. | |
27 | ||
28 | Copyright (C) 1991, 1993 Free Software Foundation, Inc. | |
29 | ||
30 | This file is part of GNU Bash, the Bourne Again SHell. | |
31 | ||
32 | Bash is free software; you can redistribute it and/or modify it | |
33 | under the terms of the GNU General Public License as published by | |
34 | the Free Software Foundation; either version 1, or (at your option) | |
35 | any later version. | |
36 | ||
37 | Bash is distributed in the hope that it will be useful, but WITHOUT | |
38 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
39 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
40 | License for more details. | |
41 | ||
42 | You should have received a copy of the GNU General Public License | |
43 | along with Bash; see the file COPYING. If not, write to the Free | |
44 | Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
45 | @end format | |
46 | @end ifinfo | |
47 | ||
48 | @titlepage | |
49 | @sp 10 | |
50 | @title Bash Features | |
51 | @subtitle Overview Documentation for Bash | |
52 | @subtitle Edition @value{EDITION}, for @code{bash} Version @value{VERSION}. | |
53 | @subtitle @value{UPDATE-MONTH} | |
54 | @author Brian Fox, Free Software Foundation | |
55 | @author Chet Ramey, Case Western Reserve University | |
56 | @page | |
57 | @vskip 0pt plus 1filll | |
58 | Copyright @copyright{} 1991, 1993 Free Software Foundation, Inc. | |
59 | @end titlepage | |
60 | ||
61 | @ifinfo | |
62 | @node Top | |
63 | @top Bash Features | |
64 | ||
65 | Bash contains features that appear in other popular shells, and some | |
66 | features that only appear in Bash. Some of the shells that Bash has | |
67 | borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell | |
68 | (@file{ksh}), and the C-shell (@file{csh} and its successor, | |
69 | @file{tcsh}). The following menu breaks the features up into | |
70 | categories based upon which one of these other shells inspired the | |
71 | feature. | |
72 | ||
73 | This manual is meant as a brief introduction to features found in | |
74 | Bash. The Bash manual page should be used as the definitive | |
75 | reference on shell behavior. | |
76 | ||
77 | @menu | |
78 | * Bourne Shell Features:: Features originally found in the | |
79 | Bourne shell. | |
80 | ||
81 | * Csh Features:: Features originally found in the | |
82 | Berkeley C-Shell. | |
83 | ||
84 | * Korn Shell Features:: Features originally found in the Korn | |
85 | Shell. | |
86 | ||
87 | * Bash Specific Features:: Features found only in Bash. | |
88 | ||
89 | * Job Control:: A chapter describing what job control is | |
90 | and how bash allows you to use it. | |
91 | ||
92 | * Using History Interactively:: Chapter dealing with history expansion | |
93 | rules. | |
94 | ||
95 | * Command Line Editing:: Chapter describing the command line | |
96 | editing features. | |
97 | ||
98 | * Variable Index:: Quick reference helps you find the | |
99 | variable you want. | |
100 | ||
101 | * Concept Index:: General index for this manual. | |
102 | @end menu | |
103 | @end ifinfo | |
104 | ||
105 | @node Bourne Shell Features | |
106 | @chapter Bourne Shell Style Features | |
107 | ||
108 | Bash is an acronym for Bourne Again SHell. The Bourne shell is | |
109 | the traditional Unix shell originally written by Stephen Bourne. | |
110 | All of the Bourne shell builtin commands are available in Bash, | |
111 | and the rules for evaluation and quoting are taken from the Posix | |
112 | 1003.2 specification for the `standard' Unix shell. | |
113 | ||
114 | This section briefly summarizes things which Bash inherits from | |
115 | the Bourne shell: shell control structures, builtins, variables, | |
116 | and other features. It also lists the significant differences | |
117 | between Bash and the Bourne Shell. | |
118 | ||
119 | @menu | |
120 | * Looping Constructs:: Shell commands for iterative action. | |
121 | * Conditional Constructs:: Shell commands for conditional execution. | |
122 | * Shell Functions:: Grouping commands by name. | |
123 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
124 | Shell. | |
125 | * Bourne Shell Variables:: Variables which Bash uses in the same way | |
126 | as the Bourne Shell. | |
127 | * Other Bourne Shell Features:: Addtional aspects of Bash which behave in | |
128 | the same way as the Bourne Shell. | |
129 | @end menu | |
130 | ||
131 | @node Looping Constructs | |
132 | @section Looping Constructs | |
133 | ||
134 | Note that wherever you see a @samp{;} in the description of a | |
135 | command's syntax, it may be replaced indiscriminately with | |
136 | one or more newlines. | |
137 | ||
138 | Bash supports the following looping constructs. | |
139 | ||
140 | @ftable @code | |
141 | @item until | |
142 | The syntax of the @code{until} command is: | |
143 | @example | |
144 | until @var{test-commands}; do @var{consequent-commands}; done | |
145 | @end example | |
146 | Execute @var{consequent-commands} as long as the final command in | |
147 | @var{test-commands} has an exit status which is not zero. | |
148 | ||
149 | @item while | |
150 | The syntax of the @code{while} command is: | |
151 | @example | |
152 | while @var{test-commands}; do @var{consequent-commands}; done | |
153 | @end example | |
154 | ||
155 | Execute @var{consequent-commands} as long as the final command in | |
156 | @var{test-commands} has an exit status of zero. | |
157 | ||
158 | @item for | |
159 | The syntax of the for command is: | |
160 | ||
161 | @example | |
162 | for @var{name} [in @var{words} ...]; do @var{commands}; done | |
163 | @end example | |
164 | Execute @var{commands} for each member in @var{words}, with @var{name} | |
165 | bound to the current member. If ``@code{in @var{words}}'' is not | |
166 | present, ``@code{in "$@@"}'' is assumed. | |
167 | ||
168 | @end ftable | |
169 | ||
170 | @node Conditional Constructs | |
171 | @section Conditional Constructs | |
172 | ||
173 | @ftable @code | |
174 | @item if | |
175 | The syntax of the @code{if} command is: | |
176 | ||
177 | @example | |
178 | if @var{test-commands}; then | |
179 | @var{consequent-commands}; | |
180 | [elif @var{more-test-commands}; then | |
181 | @var{more-consequents};] | |
182 | [else @var{alternate-consequents};] | |
183 | fi | |
184 | @end example | |
185 | ||
186 | Execute @var{consequent-commands} only if the final command in | |
187 | @var{test-commands} has an exit status of zero. | |
188 | Otherwise, each @code{elif} list is executed in turn, | |
189 | and if its exit status is zero, | |
190 | the corresponding @var{more-consequents} is executed and the | |
191 | command completes. | |
192 | If ``@code{else @var{alternate-consequents}}'' is present, and | |
193 | the final command in the final @code{if} or @code{elif} clause | |
194 | has a non-zero exit status, then execute @var{alternate-consequents}. | |
195 | ||
196 | @item case | |
197 | The syntax of the @code{case} command is: | |
198 | ||
199 | @example | |
200 | @code{case @var{word} in [@var{pattern} [| @var{pattern}]...) @var{commands} ;;]... esac} | |
201 | @end example | |
202 | ||
203 | Selectively execute @var{commands} based upon @var{word} matching | |
204 | @var{pattern}. The `@code{|}' is used to separate multiple patterns. | |
205 | ||
206 | Here is an example using @code{case} in a script that could be used to | |
207 | describe an interesting feature of an animal: | |
208 | ||
209 | @example | |
210 | echo -n "Enter the name of an animal: " | |
211 | read ANIMAL | |
212 | echo -n "The $ANIMAL has " | |
213 | case $ANIMAL in | |
214 | horse | dog | cat) echo -n "four";; | |
215 | man | kangaroo ) echo -n "two";; | |
216 | *) echo -n "an unknown number of";; | |
217 | esac | |
218 | echo "legs." | |
219 | @end example | |
220 | ||
221 | @end ftable | |
222 | ||
223 | @node Shell Functions | |
224 | @section Shell Functions | |
225 | ||
226 | Shell functions are a way to group commands for later execution | |
227 | using a single name for the group. They are executed just like | |
228 | a "regular" command. Shell functions are executed in the current | |
229 | shell context; no new process is created to interpret them. | |
230 | ||
231 | Functions are declared using this syntax: | |
232 | ||
233 | @example | |
234 | [ @code{function} ] @var{name} () @{ @var{command-list}; @} | |
235 | @end example | |
236 | ||
237 | This defines a function named @var{name}. The @var{body} of the | |
238 | function is the @var{command-list} between @{ and @}. This list | |
239 | is executed whenever @var{name} is specified as the | |
240 | name of a command. The exit status of a function is | |
241 | the exit status of the last command executed in the body. | |
242 | ||
243 | When a function is executed, the arguments to the | |
244 | function become the positional parameters | |
245 | during its execution. The special parameter | |
246 | @code{#} that gives the number of positional parameters | |
247 | is updated to reflect the change. Positional parameter 0 | |
248 | is unchanged. | |
249 | ||
250 | If the builtin command @code{return} | |
251 | is executed in a function, the function completes and | |
252 | execution resumes with the next command after the function | |
253 | call. When a function completes, the values of the | |
254 | positional parameters and the special parameter @code{#} | |
255 | are restored to the values they had prior to function | |
256 | execution. | |
257 | ||
258 | @node Bourne Shell Builtins | |
259 | @section Bourne Shell Builtins | |
260 | ||
261 | The following shell builtin commands are inherited from the Bourne | |
262 | shell. These commands are implemented as specified by the Posix | |
263 | 1003.2 standard. | |
264 | ||
265 | @ftable @code | |
266 | @item : | |
267 | Do nothing beyond expanding any arguments and performing redirections. | |
268 | @item . | |
269 | Read and execute commands from the @var{filename} argument in the | |
270 | current shell context. | |
271 | @item break | |
272 | Exit from a @code{for}, @code{while}, or @code{until} loop. | |
273 | @item cd | |
274 | Change the current working directory. | |
275 | @item continue | |
276 | Resume the next iteration of an enclosing @code{for}, @code{while}, | |
277 | or @code{until} loop. | |
278 | @item echo | |
279 | Print the arguments, separated by spaces, to the standard output. | |
280 | @item eval | |
281 | The arguments are concatenated together into a single | |
282 | command, which is then read and executed. | |
283 | @item exec | |
284 | If a @var{command} argument | |
285 | is supplied, it replaces the shell. If no | |
286 | @var{command} is specified, redirections may be used to affect | |
287 | the current shell environment. | |
288 | @item exit | |
289 | Exit the shell. | |
290 | @item export | |
291 | Mark the arguments as variables to be passed to child processes | |
292 | in the environment. | |
293 | @item getopts | |
294 | Parse options to shell scripts or functions. | |
295 | @item hash | |
296 | Remember the full pathnames of commands specified as arguments, | |
297 | so they need not be searched for on subsequent invocations. | |
298 | @item kill | |
299 | Send a signal to a process. | |
300 | @item pwd | |
301 | Print the current working directory. | |
302 | @item read | |
303 | Read a line from the shell input and use it to set the values of | |
304 | specified variables. | |
305 | @item readonly | |
306 | Mark variables as unchangable. | |
307 | @item return | |
308 | Cause a shell function to exit with a specified value. | |
309 | @item shift | |
310 | Shift positional parameters to the left. | |
311 | @item test | |
312 | @itemx [ | |
313 | Evaluate a conditional expression. | |
314 | @item times | |
315 | Print out the user and system times used by the shell and its children. | |
316 | @item trap | |
317 | Specify commands to be executed when the shell receives signals. | |
318 | @item umask | |
319 | Set the shell process's file creation mask. | |
320 | @item unset | |
321 | Cause shell variables to disappear. | |
322 | @item wait | |
323 | Wait until child processes exit and report their exit status. | |
324 | @end ftable | |
325 | ||
326 | @node Bourne Shell Variables | |
327 | @section Bourne Shell Variables | |
328 | ||
329 | Bash uses certain shell variables in the same way as the Bourne shell. | |
330 | In some cases, Bash assigns a default value to the variable. | |
331 | ||
332 | @vtable @code | |
333 | ||
334 | @item IFS | |
335 | A list of characters that separate fields; used when the shell splits | |
336 | words as part of expansion. | |
337 | ||
338 | @item PATH | |
339 | A colon-separated list of directories in which the shell looks for | |
340 | commands. | |
341 | ||
342 | @item HOME | |
343 | The current user's home directory. | |
344 | ||
345 | @item CDPATH | |
346 | A colon-separated list of directories used as a search path for | |
347 | the @code{cd} command. | |
348 | ||
349 | @item MAILPATH | |
350 | A colon-separated list of files which the shell periodically checks | |
351 | for new mail. You can | |
352 | also specify what message is printed by separating the file name from | |
353 | the message with a @samp{?}. When used in the text of the message, | |
354 | @code{$_} stands for the name of the current mailfile. | |
355 | ||
356 | @item PS1 | |
357 | The primary prompt string. | |
358 | ||
359 | @item PS2 | |
360 | The secondary prompt string. | |
361 | ||
362 | @item OPTIND | |
363 | The index of the last option processed by the | |
364 | @code{getopts} builtin. | |
365 | ||
366 | @item OPTARG | |
367 | The value of the last option argument processed by the | |
368 | @code{getopts} builtin. | |
369 | ||
370 | @end vtable | |
371 | ||
372 | @node Other Bourne Shell Features | |
373 | @section Other Bourne Shell Features | |
374 | ||
375 | @menu | |
376 | * Major Differences from the Bourne Shell:: Major differences between | |
377 | Bash and the Bourne shell. | |
378 | @end menu | |
379 | ||
380 | Bash implements essentially the same grammar, parameter and variable | |
381 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the | |
382 | Posix 1003.2 standard as the specification of how these features are to be | |
383 | implemented. There are some differences between the traditional Bourne | |
384 | shell and the Posix standard; this section quickly details the differences | |
385 | of significance. A number of these differences are explained in greater | |
386 | depth in subsequent sections. | |
387 | ||
388 | @node Major Differences from the Bourne Shell | |
389 | @subsection Major Differences from the Bourne Shell | |
390 | ||
391 | Bash implements the @code{!} keyword to negate the return value of | |
392 | a pipeline. Very useful when an @code{if} statement needs to act | |
393 | only if a test fails. | |
394 | ||
395 | Bash includes brace expansion (@pxref{Brace Expansion}). | |
396 | ||
397 | Bash includes the Posix and @code{ksh}-style pattern removal @code{%%} and | |
398 | @code{##} constructs to remove leading or trailing substrings from | |
399 | variables. | |
400 | ||
401 | The Posix and @code{ksh}-style @code{$()} form of command substitution is | |
402 | implemented, and preferred to the Bourne shell's @code{``} (which | |
403 | is also implemented for backwards compatibility). | |
404 | ||
405 | Variables present in the shell's initial environment are automatically | |
406 | exported to child processes. The Bourne shell does not normally do | |
407 | this unless the variables are explicitly marked using the @code{export} | |
408 | command. | |
409 | ||
410 | The expansion @code{$@{#xx@}}, which returns the length of @code{$xx}, | |
411 | is supported. | |
412 | ||
413 | The @code{IFS} variable is used to split only the results of expansion, | |
414 | not all words. This closes a longstanding shell security hole. | |
415 | ||
416 | It is possible to have a variable and a function with the same name; | |
417 | @code{sh} does not separate the two name spaces. | |
418 | ||
419 | Bash functions are permitted to have local variables, and thus useful | |
420 | recursive functions may be written. | |
421 | ||
422 | The @code{noclobber} option is available to avoid overwriting existing | |
423 | files with output redirection. | |
424 | ||
425 | Bash allows you to write a function to override a builtin, and provides | |
426 | access to that builtin's functionality within the function via the | |
427 | @code{builtin} and @code{command} builtins. | |
428 | ||
429 | The @code{command} builtin allows selective disabling of functions | |
430 | when command lookup is performed. | |
431 | ||
432 | Individual builtins may be enabled or disabled using the @code{enable} | |
433 | builtin. | |
434 | ||
435 | Functions may be exported to children via the environment. | |
436 | ||
437 | The Bash @code{read} builtin will read a line ending in @key{\} with | |
438 | the @code{-r} option, and will use the @code{$REPLY} variable as a | |
439 | default if no arguments are supplied. | |
440 | ||
441 | The @code{return} builtin may be used to abort execution of scripts | |
442 | executed with the @code{.} or @code{source} builtins. | |
443 | ||
444 | The @code{umask} builtin allows symbolic mode arguments similar to | |
445 | those accepted by @code{chmod}. | |
446 | ||
447 | The @code{test} builtin is slightly different, as it implements the | |
448 | Posix 1003.2 algorithm, which specifies the behavior based on the | |
449 | number of arguments. | |
450 | ||
451 | @node Csh Features | |
452 | @chapter C-Shell Style Features | |
453 | ||
454 | The C-Shell (@dfn{@code{csh}}) was created by Bill Joy at UC Berkeley. It | |
455 | is generally considered to have better features for interactive use than | |
456 | the original Bourne shell. Some of the @code{csh} features present in | |
457 | Bash include job control, history expansion, `protected' redirection, and | |
458 | several variables for controlling the interactive behaviour of the shell | |
459 | (e.g. @code{IGNOREEOF}). | |
460 | ||
461 | @xref{Using History Interactively} for details on history expansion. | |
462 | ||
463 | @menu | |
464 | * Tilde Expansion:: Expansion of the ~ character. | |
465 | * Brace Expansion:: Expansion of expressions within braces. | |
466 | * C Shell Builtins:: Builtin commands adopted from the C Shell. | |
467 | * C Shell Variables:: Variables which Bash uses in essentially | |
468 | the same way as the C Shell. | |
469 | @end menu | |
470 | ||
471 | @node Tilde Expansion | |
472 | @section Tilde Expansion | |
473 | ||
474 | Bash has tilde (~) expansion, similar, but not identical, to that of | |
475 | @code{csh}. The following table shows what unquoted words beginning | |
476 | with a tilde expand to. | |
477 | ||
478 | @table @code | |
479 | @item ~ | |
480 | The current value of @code{$HOME}. | |
481 | @item ~/foo | |
482 | @file{$HOME/foo} | |
483 | ||
484 | @item ~fred/foo | |
485 | The subdirectory @code{foo} of the home directory of the user | |
486 | @code{fred}. | |
487 | ||
488 | @item ~+/foo | |
489 | @file{$PWD/foo} | |
490 | ||
491 | @item ~- | |
492 | @file{$OLDPWD/foo} | |
493 | @end table | |
494 | ||
495 | Bash will also tilde expand words following redirection operators | |
496 | and words following @samp{=} in assignment statements. | |
497 | ||
498 | @node Brace Expansion | |
499 | @section Brace Expansion | |
500 | ||
501 | Brace expansion | |
502 | is a mechanism by which arbitrary strings | |
503 | may be generated. This mechanism is similar to | |
504 | @var{pathname expansion} (see the Bash manual | |
505 | page for details), but the file names generated | |
506 | need not exist. Patterns to be brace expanded take | |
507 | the form of an optional @var{preamble}, | |
508 | followed by a series of comma-separated strings | |
509 | between a pair of braces, followed by an optional @var{postamble}. | |
510 | The preamble is prepended to each string contained | |
511 | within the braces, and the postamble is then appended | |
512 | to each resulting string, expanding left to right. | |
513 | ||
514 | Brace expansions may be nested. The results of each expanded | |
515 | string are not sorted; left to right order is preserved. | |
516 | For example, | |
517 | @example | |
518 | a@{d,c,b@}e | |
519 | @end example | |
520 | expands into | |
521 | @var{ade ace abe}. | |
522 | ||
523 | Brace expansion is performed before any other expansions, | |
524 | and any characters special to other expansions are preserved | |
525 | in the result. It is strictly textual. Bash | |
526 | does not apply any syntactic interpretation to the context of the | |
527 | expansion or the text between the braces. | |
528 | ||
529 | A correctly-formed brace expansion must contain unquoted opening | |
530 | and closing braces, and at least one unquoted comma. | |
531 | Any incorrectly formed brace expansion is left unchanged. | |
532 | ||
533 | This construct is typically used as shorthand when the common | |
534 | prefix of the strings to be generated is longer than in the | |
535 | above example: | |
536 | @example | |
537 | mkdir /usr/local/src/bash/@{old,new,dist,bugs@} | |
538 | @end example | |
539 | or | |
540 | @example | |
541 | chown root /usr/@{ucb/@{ex,edit@},lib/@{ex?.?*,how_ex@}@} | |
542 | @end example | |
543 | ||
544 | @node C Shell Builtins | |
545 | @section C Shell Builtins | |
546 | ||
547 | Bash has several builtin commands whose definition is very similar | |
548 | to @code{csh}. | |
549 | ||
550 | @ftable @code | |
551 | @item pushd | |
552 | @example | |
553 | pushd [@var{dir} | @var{+n} | @var{-n}] | |
554 | @end example | |
555 | ||
556 | Save the current directory on a list and then @code{cd} to | |
557 | @var{dir}. With no | |
558 | arguments, exchanges the top two directories. | |
559 | ||
560 | @table @code | |
561 | @item +@var{n} | |
562 | Brings the @var{n}th directory (counting from the left of the | |
563 | list printed by @code{dirs}) to the top of the list by rotating | |
564 | the stack. | |
565 | @item -@var{n} | |
566 | Brings the @var{n}th directory (counting from the right of the | |
567 | list printed by @code{dirs}) to the top of the list by rotating | |
568 | the stack. | |
569 | @item @var{dir} | |
570 | Makes the current working directory be the top of the stack, and then | |
571 | @var{cd}s to @var{dir}. You can see the saved directory list | |
572 | with the @code{dirs} command. | |
573 | @end table | |
574 | ||
575 | @item popd | |
576 | @example | |
577 | popd [+@var{n} | -@var{n}] | |
578 | @end example | |
579 | ||
580 | Pops the directory stack, and @code{cd}s to the new top directory. When | |
581 | no arguments are given, removes the top directory from the stack and | |
582 | @code{cd}s to the new top directory. The | |
583 | elements are numbered from 0 starting at the first directory listed with | |
584 | @code{dirs}; i.e. @code{popd} is equivalent to @code{popd +0}. | |
585 | @table @code | |
586 | @item +@var{n} | |
587 | Removes the @var{n}th directory (counting from the left of the | |
588 | list printed by @code{dirs}), starting with zero. | |
589 | @item -@var{n} | |
590 | Removes the @var{n}th directory (counting from the right of the | |
591 | list printed by @code{dirs}), starting with zero. | |
592 | @end table | |
593 | ||
594 | @item dirs | |
595 | @example | |
596 | dirs [+@var{n} | -@var{n}] [-@var{l}] | |
597 | @end example | |
598 | Display the list of currently remembered directories. Directories | |
599 | find their way onto the list with the @code{pushd} command; you can get | |
600 | back up through the list with the @code{popd} command. | |
601 | @table @code | |
602 | @item +@var{n} | |
603 | Displays the @var{n}th directory (counting from the left of the | |
604 | list printed by @code{dirs} when invoked without options), starting | |
605 | with zero. | |
606 | @item -@var{n} | |
607 | Displays the @var{n}th directory (counting from the right of the | |
608 | list printed by @code{dirs} when invoked without options), starting | |
609 | with zero. | |
610 | @item -@var{l} | |
611 | Produces a longer listing; the default listing format uses a | |
612 | tilde to denote the home directory. | |
613 | @end table | |
614 | ||
615 | ||
616 | @item history | |
617 | @example | |
618 | history [@var{n}] [ [-w -r -a -n] [@var{filename}]] | |
619 | @end example | |
620 | ||
621 | Display the history list with line numbers. Lines prefixed with | |
622 | with a @code{*} have been modified. An argument of @var{n} says | |
623 | to list only the last @var{n} lines. Option @code{-w} means | |
624 | write out the current history to the history file; @code{-r} | |
625 | means to read the current history file and make its contents the | |
626 | history list. An argument of @code{-a} means to append the new | |
627 | history lines (history lines entered since the beginning of the | |
628 | current Bash session) to the history file. Finally, the | |
629 | @code{-n} argument means to read the history lines not already | |
630 | read from the history file into the current history list. These | |
631 | are lines appended to the history file since the beginning of the | |
632 | current Bash session. If @var{filename} is given, then it is used | |
633 | as the history file, else if @code{$HISTFILE} has a value, | |
634 | that is used, otherwise @file{~/.bash_history} is used. | |
635 | ||
636 | @item logout | |
637 | Exit a login shell. | |
638 | ||
639 | @item source | |
640 | A synonym for @code{.} (@pxref{Bourne Shell Builtins}) | |
641 | ||
642 | @end ftable | |
643 | ||
644 | @node C Shell Variables | |
645 | @section C Shell Variables | |
646 | ||
647 | @vtable @code | |
648 | ||
649 | @item IGNOREEOF | |
650 | If this variable is set, it represents the number of consecutive | |
651 | @code{EOF}s Bash will read before exiting. By default, Bash will exit | |
652 | upon reading a single @code{EOF}. | |
653 | ||
654 | @item cdable_vars | |
655 | If this variable is set, Bash treats arguments to the @code{cd} command | |
656 | which are not directories as names of variables whose values are the | |
657 | directories to change to. | |
658 | @end vtable | |
659 | ||
660 | @node Korn Shell Features | |
661 | @chapter Korn Shell Style Features | |
662 | ||
663 | This section describes features primarily inspired by the | |
664 | Korn Shell (@code{ksh}). In some cases, the Posix 1003.2 | |
665 | standard has adopted these commands and variables from the | |
666 | Korn Shell; Bash implements those features using the Posix | |
667 | standard as a guide. | |
668 | ||
669 | @menu | |
670 | * Korn Shell Constructs:: Shell grammar constructs adopted from the | |
671 | Korn Shell | |
672 | * Korn Shell Builtins:: Builtin commands adopted from the Korn Shell. | |
673 | * Korn Shell Variables:: Variables which bash uses in essentially | |
674 | the same way as the Korn Shell. | |
675 | * Aliases:: Substituting one command for another. | |
676 | @end menu | |
677 | ||
678 | @node Korn Shell Constructs | |
679 | @section Korn Shell Constructs | |
680 | ||
681 | Bash includes the Korn Shell @code{select} construct. This construct | |
682 | allows the easy generation of menus. It has almost the same syntax as | |
683 | the @code{for} command. | |
684 | ||
685 | The syntax of the @code{select} command is: | |
686 | @example | |
687 | select @var{name} [in @var{words} ...]; do @var{commands}; done | |
688 | @end example | |
689 | ||
690 | The list of words following @code{in} is expanded, generating a list | |
691 | of items. The set of expanded words is printed on the standard | |
692 | error, each preceded by a number. If the ``@code{in @var{words}}'' | |
693 | is omitted, the positional parameters are printed. The | |
694 | @code{PS3} prompt is then displayed and a line is read from the standard | |
695 | input. If the line consists of the number corresponding to one of | |
696 | the displayed words, then the value of @var{name} | |
697 | is set to that word. If the line is empty, the words and prompt | |
698 | are displayed again. If @code{EOF} is read, the @code{select} | |
699 | command completes. Any other value read causes @var{name} | |
700 | to be set to null. The line read is saved in the variable | |
701 | @code{REPLY}. | |
702 | ||
703 | The @var{commands} are executed after each selection until a | |
704 | @code{break} or @code{return} command is executed, at which | |
705 | point the @code{select} command completes. | |
706 | ||
707 | @node Korn Shell Builtins | |
708 | @section Korn Shell Builtins | |
709 | ||
710 | This section describes Bash builtin commands taken from @code{ksh}. | |
711 | ||
712 | @ftable @code | |
713 | @item fc | |
714 | ||
715 | @example | |
716 | @code{fc [-e @var{ename}] [-nlr] [@var{first}] [@var{last}]} | |
717 | @code{fc -s [@var{pat=rep}] [@var{command}]} | |
718 | @end example | |
719 | ||
720 | Fix Command. In the first form, a range of commands from @var{first} to | |
721 | @var{last} is selected from the history list. Both @var{first} and | |
722 | @var{last} may be specified as a string (to locate the most recent | |
723 | command beginning with that string) or as a number (an index into the | |
724 | history list, where a negative number is used as an offset from the | |
725 | current command number). If @var{last} is not specified it is set to | |
726 | @var{first}. If @var{first} is not specified it is set to the previous | |
727 | command for editing and -16 for listing. If the @code{-l} flag is | |
728 | given, the commands are listed on standard output. The @code{-n} flag | |
729 | suppresses the command numbers when listing. The @code{-r} flag | |
730 | reverses the order of the listing. Otherwise, the editor given by | |
731 | @var{ename} is invoked on a file containing those commands. If | |
732 | @var{ename} is not given, the value of the following variable expansion | |
733 | is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the | |
734 | value of the @code{FCEDIT} variable if set, or the value of the | |
735 | @code{EDITOR} variable if that is set, or @code{vi} if neither is set. | |
736 | When editing is complete, the edited commands are echoed and executed. | |
737 | ||
738 | In the second form, @var{command} is re-executed after each instance | |
739 | of @var{pat} in the selected command is replaced by @var{rep}. | |
740 | ||
741 | A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so | |
742 | that typing @code{r cc} runs the last command beginning with @code{cc} | |
743 | and typing @code{r} re-executes the last command (@pxref{Aliases}). | |
744 | ||
745 | @item let | |
746 | The @code{let} builtin allows arithmetic to be performed on shell variables. | |
747 | For details, refer to @ref{Arithmetic Builtins}. | |
748 | ||
749 | @item typeset | |
750 | The @code{typeset} command is supplied for compatibility with the Korn | |
751 | shell; however, it has been made obsolete by the | |
752 | @code{declare} command (@pxref{Bash Builtins}). | |
753 | ||
754 | @end ftable | |
755 | ||
756 | @node Korn Shell Variables | |
757 | @section Korn Shell Variables | |
758 | ||
759 | @vtable @code | |
760 | ||
761 | @item REPLY | |
762 | The default variable for the @code{read} builtin. | |
763 | ||
764 | @item RANDOM | |
765 | Each time this parameter is referenced, a random integer | |
766 | is generated. Assigning a value to this variable seeds | |
767 | the random number generator. | |
768 | ||
769 | @item SECONDS | |
770 | This variable expands to the number of seconds since the | |
771 | shell was started. Assignment to this variable resets | |
772 | the count to the value assigned, and the expanded value | |
773 | becomes the value assigned plus the number of seconds | |
774 | since the assignment. | |
775 | ||
776 | @item PS3 | |
777 | The value of this variable is used as the prompt for the | |
778 | @code{select} command. | |
779 | ||
780 | @item PS4 | |
781 | This is the prompt printed before the command line is echoed | |
782 | when the @code{-x} option is set (@pxref{The Set Builtin}). | |
783 | ||
784 | @item PWD | |
785 | The current working directory as set by the @code{cd} builtin. | |
786 | ||
787 | @item OLDPWD | |
788 | The previous working directory as set by the @code{cd} builtin. | |
789 | ||
790 | @item TMOUT | |
791 | If set to a value greater than zero, the value is interpreted as | |
792 | the number of seconds to wait for input after issuing the primary | |
793 | prompt. | |
794 | Bash terminates after that number of seconds if input does | |
795 | not arrive. | |
796 | ||
797 | @end vtable | |
798 | ||
799 | @node Aliases | |
800 | @section Aliases | |
801 | ||
802 | @menu | |
803 | * Alias Builtins:: Builtins commands to maniuplate aliases. | |
804 | @end menu | |
805 | ||
806 | The shell maintains a list of @var{aliases} | |
807 | that may be set and unset with the @code{alias} and | |
808 | @code{unalias} builtin commands. | |
809 | ||
810 | The first word of each command, if unquoted, | |
811 | is checked to see if it has an | |
812 | alias. If so, that word is replaced by the text of the alias. | |
813 | The alias name and the replacement text may contain any valid | |
814 | shell input, including shell metacharacters, with the exception | |
815 | that the alias name may not contain @key{=}. | |
816 | The first word of the replacement text is tested for | |
817 | aliases, but a word that is identical to an alias being expanded | |
818 | is not expanded a second time. This means that one may alias | |
819 | @code{ls} to @code{"ls -F"}, | |
820 | for instance, and Bash does not try to recursively expand the | |
821 | replacement text. If the last character of the alias value is a | |
822 | space or tab character, then the next command word following the | |
823 | alias is also checked for alias expansion. | |
824 | ||
825 | Aliases are created and listed with the @code{alias} | |
826 | command, and removed with the @code{unalias} command. | |
827 | ||
828 | There is no mechanism for using arguments in the replacement text, | |
829 | as in @code{csh}. | |
830 | If arguments are needed, a shell function should be used. | |
831 | ||
832 | Aliases are not expanded when the shell is not interactive. | |
833 | ||
834 | The rules concerning the definition and use of aliases are | |
835 | somewhat confusing. Bash | |
836 | always reads at least one complete line | |
837 | of input before executing any | |
838 | of the commands on that line. Aliases are expanded when a | |
839 | command is read, not when it is executed. Therefore, an | |
840 | alias definition appearing on the same line as another | |
841 | command does not take effect until the next line of input is read. | |
842 | This means that the commands following the alias definition | |
843 | on that line are not affected by the new alias. | |
844 | This behavior is also an issue when functions are executed. | |
845 | Aliases are expanded when the function definition is read, | |
846 | not when the function is executed, because a function definition | |
847 | is itself a compound command. As a consequence, aliases | |
848 | defined in a function are not available until after that | |
849 | function is executed. To be safe, always put | |
850 | alias definitions on a separate line, and do not use @code{alias} | |
851 | in compound commands. | |
852 | ||
853 | Note that for almost every purpose, aliases are superseded by | |
854 | shell functions. | |
855 | ||
856 | @node Alias Builtins | |
857 | @subsection Alias Builtins | |
858 | ||
859 | @ftable @code | |
860 | @item alias | |
861 | @example | |
862 | alias [@var{name}[=@var{value}] ...] | |
863 | @end example | |
864 | ||
865 | Without arguments, print the list of aliases on the standard output. | |
866 | If arguments are supplied, an alias is defined for each @var{name} | |
867 | whose @var{value} is given. If no @var{value} is given, the name | |
868 | and value of the alias is printed. | |
869 | ||
870 | @item unalias | |
871 | @example | |
872 | unalias [-a] [@var{name} ... ] | |
873 | @end example | |
874 | ||
875 | Remove each @var{name} from the list of aliases. If @code{-a} is | |
876 | supplied, all aliases are removed. | |
877 | @end ftable | |
878 | ||
879 | @node Bash Specific Features | |
880 | @chapter Bash Specific Features | |
881 | ||
882 | This section describes the features unique to Bash. | |
883 | ||
884 | @menu | |
885 | * Invoking Bash:: Command line options that you can give | |
886 | to Bash. | |
887 | * Bash Startup Files:: When and how Bash executes scripts. | |
888 | * Is This Shell Interactive?:: Determining the state of a running Bash. | |
889 | * Bash Builtins:: Table of builtins specific to Bash. | |
890 | * The Set Builtin:: This builtin is so overloaded it | |
891 | deserves its own section. | |
892 | * Bash Variables:: List of variables that exist in Bash. | |
893 | * Shell Arithmetic:: Arithmetic on shell variables. | |
894 | * Printing a Prompt:: Controlling the PS1 string. | |
895 | @end menu | |
896 | ||
897 | @node Invoking Bash | |
898 | @section Invoking Bash | |
899 | ||
900 | In addition to the single-character shell command-line options | |
901 | (@pxref{The Set Builtin}), there are several multi-character | |
902 | options that you can use. These options must appear on the command | |
903 | line before the single-character options to be recognized. | |
904 | ||
905 | @table @code | |
906 | @item -norc | |
907 | Don't read the @file{~/.bashrc} initialization file in an | |
908 | interactive shell. This is on by default if the shell is | |
909 | invoked as @code{sh}. | |
910 | ||
911 | @item -rcfile @var{filename} | |
912 | Execute commands from @var{filename} (instead of @file{~/.bashrc}) | |
913 | in an interactive shell. | |
914 | ||
915 | @item -noprofile | |
916 | Don't load the system-wide startup file @file{/etc/profile} | |
917 | or any of the personal initialization files | |
918 | @file{~/.bash_profile}, @file{~/.bash_login}, or @file{~/.profile} | |
919 | when bash is invoked as a login shell. | |
920 | ||
921 | @item -version | |
922 | Display the version number of this shell. | |
923 | ||
924 | @item -login | |
925 | Make this shell act as if it were directly invoked from login. | |
926 | This is equivalent to @samp{exec - bash} but can be issued from | |
927 | another shell, such as @code{csh}. If you wanted to replace your | |
928 | current login shell with a Bash login shell, you would say | |
929 | @samp{exec bash -login}. | |
930 | ||
931 | @item -nobraceexpansion | |
932 | Do not perform curly brace expansion (@pxref{Brace Expansion}). | |
933 | ||
934 | @item -nolineediting | |
935 | Do not use the GNU Readline library (@pxref{Command Line Editing}) | |
936 | to read interactive command lines. | |
937 | ||
938 | @item -posix | |
939 | Change the behavior of Bash where the default operation differs | |
940 | from the Posix 1003.2 standard to match the standard. This | |
941 | is intended to make Bash behave as a strict superset of that | |
942 | standard. | |
943 | ||
944 | @end table | |
945 | ||
946 | There are several single-character options you can give which are | |
947 | not available with the @code{set} builtin. | |
948 | ||
949 | @table @code | |
950 | @item -c @var{string} | |
951 | Read and execute commands from @var{string} after processing the | |
952 | options, then exit. | |
953 | ||
954 | @item -i | |
955 | Force the shell to run interactively. | |
956 | ||
957 | @item -s | |
958 | If this flag is present, or if no arguments remain after option | |
959 | processing, then commands are read from the standard input. | |
960 | This option allows the positional parameters to be set | |
961 | when invoking an interactive shell. | |
962 | ||
963 | @end table | |
964 | ||
965 | An @emph{interactive} shell is one whose input and output are both | |
966 | connected to terminals (as determined by @code{isatty()}), or one | |
967 | started with the @code{-i} option. | |
968 | ||
969 | @node Bash Startup Files | |
970 | @section Bash Startup Files | |
971 | ||
972 | When and how Bash executes startup files. | |
973 | ||
974 | @example | |
975 | For Login shells (subject to the -noprofile option): | |
976 | ||
977 | On logging in: | |
978 | If @file{/etc/profile} exists, then source it. | |
979 | ||
980 | If @file{~/.bash_profile} exists, then source it, | |
981 | else if @file{~/.bash_login} exists, then source it, | |
982 | else if @file{~/.profile} exists, then source it. | |
983 | ||
984 | On logging out: | |
985 | If @file{~/.bash_logout} exists, source it. | |
986 | ||
987 | For non-login interactive shells (subject to the -norc and -rcfile options): | |
988 | On starting up: | |
989 | If @file{~/.bashrc} exists, then source it. | |
990 | ||
991 | For non-interactive shells: | |
992 | On starting up: | |
993 | If the environment variable @code{ENV} is non-null, expand the | |
994 | variable and source the file named by the value. If Bash is | |
995 | not started in Posix mode, it looks for @code{BASH_ENV} before | |
996 | @code{ENV}. | |
997 | @end example | |
998 | ||
999 | So, typically, your @code{~/.bash_profile} contains the line | |
1000 | @example | |
1001 | @code{if [ -f @code{~/.bashrc} ]; then source @code{~/.bashrc}; fi} | |
1002 | @end example | |
1003 | @noindent | |
1004 | after (or before) any login specific initializations. | |
1005 | ||
1006 | If Bash is invoked as @code{sh}, it tries to mimic the behavior of | |
1007 | @code{sh} as closely as possible. For a login shell, it attempts to | |
1008 | source only @file{/etc/profile} and @file{~/.profile}, in that order. | |
1009 | The @code{-noprofile} option may still be used to disable this behavior. | |
1010 | A shell invoked as @code{sh} does not attempt to source any other | |
1011 | startup files. | |
1012 | ||
1013 | When Bash is started in @var{POSIX} mode, as with the | |
1014 | @code{-posix} command line option, it follows the Posix 1003.2 | |
1015 | standard for startup files. In this mode, the @code{ENV} | |
1016 | variable is expanded and that file sourced; no other startup files | |
1017 | are read. | |
1018 | ||
1019 | @node Is This Shell Interactive? | |
1020 | @section Is This Shell Interactive? | |
1021 | ||
1022 | You may wish to determine within a startup script whether Bash is | |
1023 | running interactively or not. To do this, examine the variable | |
1024 | @code{$PS1}; it is unset in non-interactive shells, and set in | |
1025 | interactive shells. Thus: | |
1026 | ||
1027 | @example | |
1028 | if [ -z "$PS1" ]; then | |
1029 | echo This shell is not interactive | |
1030 | else | |
1031 | echo This shell is interactive | |
1032 | fi | |
1033 | @end example | |
1034 | ||
1035 | You can ask an interactive Bash to not run your @file{~/.bashrc} file | |
1036 | with the @code{-norc} flag. You can change the name of the | |
1037 | @file{~/.bashrc} file to any other file name with @code{-rcfile | |
1038 | @var{filename}}. You can ask Bash to not run your | |
1039 | @file{~/.bash_profile} file with the @code{-noprofile} flag. | |
1040 | ||
1041 | @node Bash Builtins | |
1042 | @section Bash Builtin Commands | |
1043 | ||
1044 | This section describes builtin commands which are unique to | |
1045 | or have been extended in Bash. | |
1046 | ||
1047 | @ftable @code | |
1048 | @item builtin | |
1049 | @example | |
1050 | builtin [@var{shell-builtin} [@var{args}]] | |
1051 | @end example | |
1052 | Run a shell builtin. This is useful when you wish to rename a | |
1053 | shell builtin to be a function, but need the functionality of the | |
1054 | builtin within the function itself. | |
1055 | ||
1056 | @item bind | |
1057 | @example | |
1058 | bind [-m @var{keymap}] [-lvd] [-q @var{name}] | |
1059 | bind [-m @var{keymap}] -f @var{filename} | |
1060 | bind [-m @var{keymap}] @var{keyseq:function-name} | |
1061 | @end example | |
1062 | ||
1063 | Display current Readline (@pxref{Command Line Editing}) | |
1064 | key and function bindings, or | |
1065 | bind a key sequence to a Readline function or macro. The | |
1066 | binding syntax accepted is identical to that of | |
1067 | @file{.inputrc} (@pxref{Readline Init File}), | |
1068 | but each binding must be passed as a separate argument: | |
1069 | @samp{"\C-x\C-r":re-read-init-file}. | |
1070 | Options, if supplied, have the following meanings: | |
1071 | ||
1072 | @table @code | |
1073 | @item -m keymap | |
1074 | Use @var{keymap} as the keymap to be affected by | |
1075 | the subsequent bindings. Acceptable @var{keymap} | |
1076 | names are | |
1077 | @code{emacs}, | |
1078 | @code{emacs-standard}, | |
1079 | @code{emacs-meta}, | |
1080 | @code{emacs-ctlx}, | |
1081 | @code{vi}, | |
1082 | @code{vi-move}, | |
1083 | @code{vi-command}, and | |
1084 | @code{vi-insert}. | |
1085 | @code{vi} is equivalent to @code{vi-command}; | |
1086 | @code{emacs} is equivalent to @code{emacs-standard}. | |
1087 | ||
1088 | @item -l | |
1089 | List the names of all readline functions | |
1090 | ||
1091 | @item -v | |
1092 | List current function names and bindings | |
1093 | ||
1094 | @item -d | |
1095 | Dump function names and bindings in such a way that they can be re-read | |
1096 | ||
1097 | @item -f filename | |
1098 | Read key bindings from @var{filename} | |
1099 | ||
1100 | @item -q | |
1101 | Query about which keys invoke the named @var{function} | |
1102 | @end table | |
1103 | ||
1104 | @item command | |
1105 | @example | |
1106 | command [-pVv] @var{command} [@var{args} ...] | |
1107 | @end example | |
1108 | Runs @var{command} with @var{arg} ignoring shell functions. If | |
1109 | you have a shell function called @code{ls}, and you wish to call | |
1110 | the command @code{ls}, you can say @samp{command ls}. The | |
1111 | @code{-p} option means to use a default value for @code{$PATH} | |
1112 | that is guaranteed to find all of the standard utilities. | |
1113 | ||
1114 | If either the @code{-V} or @code{-v} option is supplied, a | |
1115 | description of @var{command} is printed. The @code{-v} option | |
1116 | causes a single word indicating the command or file name used to | |
1117 | invoke @var{command} to be printed; the @code{-V} option produces | |
1118 | a more verbose description. | |
1119 | ||
1120 | @item declare | |
1121 | @example | |
1122 | declare [-frxi] [@var{name}[=@var{value}]] | |
1123 | @end example | |
1124 | ||
1125 | Declare variables and/or give them attributes. If no @var{name}s | |
1126 | are given, then display the values of variables instead. | |
1127 | @code{-f} means to use function names only. @code{-r} says to | |
1128 | make @var{name}s readonly. @code{-x} says to mark @var{name}s | |
1129 | for export. @code{-i} says that the variable is to be treated as | |
1130 | an integer; arithmetic evaluation (@pxref{Shell Arithmetic}) is | |
1131 | performed when the variable is assigned a value. Using @code{+} | |
1132 | instead of @code{-} turns off the attribute instead. When used in | |
1133 | a function, @code{declare} makes @var{name}s local, as with the | |
1134 | @code{local} command. | |
1135 | ||
1136 | @item enable | |
1137 | @example | |
1138 | enable [-n] [-a] [@var{name} ...] | |
1139 | @end example | |
1140 | Enable and disable builtin shell commands. This allows you to | |
1141 | use a disk command which has the same name as a shell builtin. | |
1142 | If @code{-n} is used, the @var{name}s become disabled. Otherwise | |
1143 | @var{name}s are enabled. For example, to use the @code{test} binary | |
1144 | found via @code{$PATH} instead of the shell builtin version, type | |
1145 | @samp{enable -n test}. The @code{-a} option means to list | |
1146 | each builtin with an indication of whether or not it is enabled. | |
1147 | ||
1148 | @item help | |
1149 | @example | |
1150 | help [@var{pattern}] | |
1151 | @end example | |
1152 | Display helpful information about builtin commands. If | |
1153 | @var{pattern} is specified, @code{help} gives detailed help | |
1154 | on all commands matching @var{pattern}, otherwise a list of | |
1155 | the builtins is printed. | |
1156 | ||
1157 | @item local | |
1158 | @example | |
1159 | local @var{name}[=@var{value}] | |
1160 | @end example | |
1161 | For each argument, create a local variable called @var{name}, and | |
1162 | give it @var{value}. | |
1163 | @code{local} can only be used within a function; it makes the variable | |
1164 | @var{name} have a visible scope restricted to that function and its | |
1165 | children. | |
1166 | ||
1167 | @item type | |
1168 | @example | |
1169 | type [-all] [-type | -path] [@var{name} ...] | |
1170 | @end example | |
1171 | For each @var{name}, indicate how it would be interpreted if used as a | |
1172 | command name. | |
1173 | ||
1174 | If the @code{-type} flag is used, @code{type} returns a single word | |
1175 | which is one of ``alias'', ``function'', ``builtin'', ``file'' or | |
1176 | ``keyword'', if @var{name} is an alias, shell function, shell builtin, | |
1177 | disk file, or shell reserved word, respectively. | |
1178 | ||
1179 | If the @code{-path} flag is used, @code{type} either returns the name | |
1180 | of the disk file that would be executed, or nothing if @code{-type} | |
1181 | would not return ``file''. | |
1182 | ||
1183 | If the @code{-all} flag is used, returns all of the places that contain | |
1184 | an executable named @var{file}. This includes aliases and functions, | |
1185 | if and only if the @code{-path} flag is not also used. | |
1186 | ||
1187 | @code{Type} accepts @code{-a}, @code{-t}, and @code{-p} as equivalent to | |
1188 | @code{-all}, @code{-type}, and @code{-path}, respectively. | |
1189 | ||
1190 | @item ulimit | |
1191 | @example | |
1192 | ulimit [-acdmstfpnuvSH] [@var{limit}] | |
1193 | @end example | |
1194 | @code{Ulimit} provides control over the resources available to processes | |
1195 | started by the shell, on systems that allow such control. If an | |
1196 | option is given, it is interpreted as follows: | |
1197 | @table @code | |
1198 | @item -S | |
1199 | change and report the soft limit associated with a resource (the | |
1200 | default if the @code{-H} option is not given). | |
1201 | @item -H | |
1202 | change and report the hard limit associated with a resource. | |
1203 | @item -a | |
1204 | all current limits are reported. | |
1205 | ||
1206 | @item -c | |
1207 | the maximum size of core files created. | |
1208 | ||
1209 | @item -d | |
1210 | the maximum size of a process's data segment. | |
1211 | ||
1212 | @item -m | |
1213 | the maximum resident set size. | |
1214 | ||
1215 | @item -s | |
1216 | the maximum stack size. | |
1217 | ||
1218 | @item -t | |
1219 | the maximum amount of cpu time in seconds. | |
1220 | ||
1221 | @item -f | |
1222 | the maximum size of files created by the shell. | |
1223 | ||
1224 | @item -p | |
1225 | the pipe buffer size. | |
1226 | ||
1227 | @item -n | |
1228 | the maximum number of open file descriptors. | |
1229 | ||
1230 | @item -u | |
1231 | the maximum number of processes available to a single user. | |
1232 | ||
1233 | @item -v | |
1234 | the maximum amount of virtual memory available to the process. | |
1235 | ||
1236 | @end table | |
1237 | ||
1238 | If @var{limit} is given, it is the new value of the specified resource. | |
1239 | Otherwise, the current value of the specified resource is printed. If | |
1240 | no option is given, then @samp{-f} is assumed. Values are in 1024-byte | |
1241 | increments, except for @samp{-t}, which is in seconds, @samp{-p}, | |
1242 | which is in units of 512-byte blocks, and @samp{-n} and @samp{-u}, which | |
1243 | are unscaled values. | |
1244 | ||
1245 | @end ftable | |
1246 | ||
1247 | @node The Set Builtin | |
1248 | @section The Set Builtin | |
1249 | ||
1250 | This builtin is so overloaded that it deserves its own section. | |
1251 | ||
1252 | @ftable @code | |
1253 | @item set | |
1254 | @example | |
1255 | set [-abefhkmnptuvxldCHP] [-o @var{option}] [@var{argument} ...] | |
1256 | @end example | |
1257 | ||
1258 | @table @code | |
1259 | @item -a | |
1260 | Mark variables which are modified or created for export. | |
1261 | ||
1262 | @item -b | |
1263 | Cause the status of terminated background jobs to be reported | |
1264 | immediately, rather than before printing the next primary prompt. | |
1265 | ||
1266 | @item -e | |
1267 | Exit immediately if a command exits with a non-zero status. | |
1268 | ||
1269 | @item -f | |
1270 | Disable file name generation (globbing). | |
1271 | ||
1272 | @item -h | |
1273 | Locate and remember (hash) commands as functions are defined, rather | |
1274 | than when the function is executed. | |
1275 | ||
1276 | @item -k | |
1277 | All keyword arguments are placed in the environment for a command, not | |
1278 | just those that precede the command name. | |
1279 | ||
1280 | @item -m | |
1281 | Job control is enabled (@pxref{Job Control}). | |
1282 | ||
1283 | @item -n | |
1284 | Read commands but do not execute them. | |
1285 | ||
1286 | @item -o @var{option-name} | |
1287 | ||
1288 | Set the flag corresponding to @var{option-name}: | |
1289 | ||
1290 | @table @code | |
1291 | @item allexport | |
1292 | same as @code{-a}. | |
1293 | ||
1294 | @item braceexpand | |
1295 | the shell will perform brace expansion (@pxref{Brace Expansion}). | |
1296 | ||
1297 | @item emacs | |
1298 | use an emacs-style line editing interface (@pxref{Command Line Editing}). | |
1299 | ||
1300 | @item errexit | |
1301 | same as @code{-e}. | |
1302 | ||
1303 | @item histexpand | |
1304 | same as @code{-H}. | |
1305 | ||
1306 | @item ignoreeof | |
1307 | the shell will not exit upon reading EOF. | |
1308 | ||
1309 | @item interactive-comments | |
1310 | allow a word beginning with a @samp{#} to cause that word and | |
1311 | all remaining characters on that line to be ignored in an | |
1312 | interactive shell. | |
1313 | ||
1314 | @item monitor | |
1315 | same as @code{-m}. | |
1316 | ||
1317 | @item noclobber | |
1318 | same as @code{-C}. | |
1319 | ||
1320 | @item noexec | |
1321 | same as @code{-n}. | |
1322 | ||
1323 | @item noglob | |
1324 | same as @code{-f}. | |
1325 | ||
1326 | @item nohash | |
1327 | same as @code{-d}. | |
1328 | ||
1329 | @item notify | |
1330 | same as @code{-b}. | |
1331 | ||
1332 | @item nounset | |
1333 | same as @code{-u}. | |
1334 | ||
1335 | @item physical | |
1336 | same as @code{-P}. | |
1337 | ||
1338 | @item posix | |
1339 | change the behavior of Bash where the default operation differs | |
1340 | from the Posix 1003.2 standard to match the standard. This | |
1341 | is intended to make Bash behave as a strict superset of that | |
1342 | standard. | |
1343 | ||
1344 | @item privileged | |
1345 | same as @code{-p}. | |
1346 | ||
1347 | @item verbose | |
1348 | same as @code{-v}. | |
1349 | ||
1350 | @item vi | |
1351 | use a @code{vi}-style line editing interface. | |
1352 | ||
1353 | @item xtrace | |
1354 | same as @code{-x}. | |
1355 | @end table | |
1356 | ||
1357 | @item -p | |
1358 | Turn on privileged mode. | |
1359 | In this mode, the @code{$ENV} | |
1360 | file is not processed, and shell functions | |
1361 | are not inherited from the environment. This is enabled automatically | |
1362 | on startup if the effective user (group) id is not equal to the real | |
1363 | user (group) id. Turning this option off causes the effective user | |
1364 | and group ids to be set to the real user and group ids. | |
1365 | ||
1366 | @item -t | |
1367 | Exit after reading and executing one command. | |
1368 | ||
1369 | @item -u | |
1370 | Treat unset variables as an error when substituting. | |
1371 | ||
1372 | @item -v | |
1373 | Print shell input lines as they are read. | |
1374 | ||
1375 | @item -x | |
1376 | Print commands and their arguments as they are executed. | |
1377 | ||
1378 | @item -l | |
1379 | Save and restore the binding of the @var{name} in a @code{for} command. | |
1380 | ||
1381 | @item -d | |
1382 | Disable the hashing of commands that are looked up for execution. | |
1383 | Normally, commands are remembered in a hash table, and once found, do | |
1384 | not have to be looked up again. | |
1385 | ||
1386 | @item -C | |
1387 | Disallow output redirection to existing files. | |
1388 | ||
1389 | @item -H | |
1390 | Enable ! style history substitution. This flag is on by default. | |
1391 | ||
1392 | @item -P | |
1393 | If set, do not follow symbolic links when performing commands such as | |
1394 | @code{cd} which change the current directory. The physical directory | |
1395 | is used instead. | |
1396 | ||
1397 | @item -- | |
1398 | If no arguments follow this flag, then the positional parameters are | |
1399 | unset. Otherwise, the positional parameters are set to the | |
1400 | @var{arguments}, even if some of them begin with a @code{-}. | |
1401 | ||
1402 | @item - | |
1403 | Signal the end of options, cause all remaining @var{arguments} | |
1404 | to be assigned to the positional parameters. The @code{-x} | |
1405 | and @code{-v} options are turned off. | |
1406 | If there are no arguments, the positional parameters remain unchanged. | |
1407 | @end table | |
1408 | ||
1409 | Using @samp{+} rather than @samp{-} causes these flags to be | |
1410 | turned off. The flags can also be used upon invocation of the | |
1411 | shell. The current set of flags may be found in @code{$-}. The | |
1412 | remaining N @var{arguments} are positional parameters and are | |
1413 | assigned, in order, to @code{$1}, @code{$2}, .. @code{$N}. If | |
1414 | no arguments are given, all shell variables are printed. | |
1415 | @end ftable | |
1416 | ||
1417 | @node Bash Variables | |
1418 | @section Bash Variables | |
1419 | ||
1420 | These variables are set or used by bash, but other shells | |
1421 | do not normally treat them specially. | |
1422 | ||
1423 | @vtable @code | |
1424 | ||
1425 | @item HISTCONTROL | |
1426 | @itemx history_control | |
1427 | Set to a value of @samp{ignorespace}, it means don't enter lines which | |
1428 | begin with a space or tab into the history list. Set to a value | |
1429 | of @samp{ignoredups}, it means don't enter lines which match the last | |
1430 | entered line. A value of @samp{ignoreboth} combines the two options. | |
1431 | Unset, or set to any other value than those above, means to save | |
1432 | all lines on the history list. | |
1433 | ||
1434 | @item HISTFILE | |
1435 | The name of the file to which the command history is saved. | |
1436 | ||
1437 | @item HISTSIZE | |
1438 | If set, this is the maximum number of commands to remember in the | |
1439 | history. | |
1440 | ||
1441 | @item histchars | |
1442 | Up to three characters which control history expansion, quick | |
1443 | substitution, and tokenization (@pxref{History Interaction}). | |
1444 | The first character is the | |
1445 | @dfn{history-expansion-char}, that is, the character which signifies the | |
1446 | start of a history expansion, normally @samp{!}. The second character is the | |
1447 | character which signifies `quick substitution' when seen as the first | |
1448 | character on a line, normally @samp{^}. The optional third character is the | |
1449 | character which signifies the remainder of the line is a comment, when | |
1450 | found as the first character of a word, usually @samp{#}. The history | |
1451 | comment character causes history substitution to be skipped for the | |
1452 | remaining words on the line. It does not necessarily cause the shell | |
1453 | parser to treat the rest of the line as a comment. | |
1454 | ||
1455 | @item HISTCMD | |
1456 | The history number, or index in the history list, of the current | |
1457 | command. If @code{HISTCMD} is unset, it loses its special properties, | |
1458 | even if it is subsequently reset. | |
1459 | ||
1460 | @item hostname_completion_file | |
1461 | @itemx HOSTFILE | |
1462 | Contains the name of a file in the same format as @file{/etc/hosts} that | |
1463 | should be read when the shell needs to complete a hostname. You can | |
1464 | change the file interactively; the next time you attempt to complete a | |
1465 | hostname, Bash will add the contents of the new file to the already | |
1466 | existing database. | |
1467 | ||
1468 | @item MAILCHECK | |
1469 | How often (in seconds) that the shell should check for mail | |
1470 | in the files specified in @code{MAILPATH}. | |
1471 | ||
1472 | @item PROMPT_COMMAND | |
1473 | If present, this contains a string which is a command to execute | |
1474 | before the printing of each primary prompt (@code{$PS1}). | |
1475 | ||
1476 | @item UID | |
1477 | The numeric real user id of the current user. | |
1478 | ||
1479 | @item EUID | |
1480 | The numeric effective user id of the current user. | |
1481 | ||
1482 | @item HOSTTYPE | |
1483 | A string describing the machine Bash is running on. | |
1484 | ||
1485 | @item OSTYPE | |
1486 | A string describing the operating system Bash is running on. | |
1487 | ||
1488 | @item FIGNORE | |
1489 | A colon-separated list of suffixes to ignore when performing | |
1490 | filename completion | |
1491 | A file name whose suffix matches one of the entries in | |
1492 | @code{FIGNORE} | |
1493 | is excluded from the list of matched file names. A sample | |
1494 | value is @samp{.o:~} | |
1495 | ||
1496 | @item INPUTRC | |
1497 | The name of the Readline startup file, overriding the default | |
1498 | of @file{~/.inputrc}. | |
1499 | ||
1500 | @item BASH_VERSION | |
1501 | The version number of the current instance of Bash. | |
1502 | ||
1503 | @item IGNOREEOF | |
1504 | Controls the action of the shell on receipt of an @code{EOF} character | |
1505 | as the sole input. If set, then the value of it is the number | |
1506 | of consecutive @code{EOF} characters that can be read as the | |
1507 | first characters on an input line | |
1508 | before the shell will exit. If the variable exists but does not | |
1509 | have a numeric value (or has no value) then the default is 10. | |
1510 | If the variable does not exist, then @code{EOF} signifies the end of | |
1511 | input to the shell. This is only in effect for interactive shells. | |
1512 | ||
1513 | @item no_exit_on_failed_exec | |
1514 | If this variable exists, the shell will not exit in the case that it | |
1515 | couldn't execute the file specified in the @code{exec} command. | |
1516 | ||
1517 | @item nolinks | |
1518 | If present, says not to follow symbolic links when doing commands | |
1519 | that change the current working directory. By default, bash follows | |
1520 | the logical chain of directories when performing commands such as | |
1521 | @code{cd} which change the current directory. | |
1522 | ||
1523 | For example, if @file{/usr/sys} is a link to @file{/usr/local/sys} then: | |
1524 | @example | |
1525 | $ cd /usr/sys; echo $PWD | |
1526 | /usr/sys | |
1527 | $ cd ..; pwd | |
1528 | /usr | |
1529 | @end example | |
1530 | ||
1531 | @noindent | |
1532 | If @code{nolinks} exists, then: | |
1533 | @example | |
1534 | $ cd /usr/sys; echo $PWD | |
1535 | /usr/local/sys | |
1536 | $ cd ..; pwd | |
1537 | /usr/local | |
1538 | @end example | |
1539 | ||
1540 | See also the description of the @code{-P} option to the @code{set} | |
1541 | builtin, @ref{The Set Builtin}. | |
1542 | @end vtable | |
1543 | ||
1544 | @node Shell Arithmetic | |
1545 | @section Shell Arithmetic | |
1546 | ||
1547 | @menu | |
1548 | * Arithmetic Evaluation:: How shell arithmetic works. | |
1549 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. | |
1550 | * Arithmetic Builtins:: Builtin commands that use shell arithmetic. | |
1551 | @end menu | |
1552 | ||
1553 | @node Arithmetic Evaluation | |
1554 | @subsection Arithmetic Evaluation | |
1555 | ||
1556 | The shell allows arithmetic expressions to be evaluated, as one of | |
1557 | the shell expansions or by the @code{let} builtin. | |
1558 | ||
1559 | Evaluation is done in long integers with no check for overflow, | |
1560 | though division by 0 is trapped and flagged as an error. The | |
1561 | following list of operators is grouped into levels of | |
1562 | equal-precedence operators. The levels are listed in order of | |
1563 | decreasing precedence. | |
1564 | ||
1565 | @table @code | |
1566 | @item - + | |
1567 | unary minus and plus | |
1568 | ||
1569 | @item ! ~ | |
1570 | logical and bitwise negation | |
1571 | ||
1572 | @item * / % | |
1573 | multiplication, division, remainder | |
1574 | ||
1575 | @item + - | |
1576 | addition, subtraction | |
1577 | ||
1578 | @item << >> | |
1579 | left and right bitwise shifts | |
1580 | ||
1581 | @item <= >= < > | |
1582 | comparison | |
1583 | ||
1584 | @item == != | |
1585 | equality and inequality | |
1586 | ||
1587 | @item & | |
1588 | bitwise AND | |
1589 | ||
1590 | @item ^ | |
1591 | bitwise exclusive OR | |
1592 | ||
1593 | @item | | |
1594 | bitwise OR | |
1595 | ||
1596 | @item && | |
1597 | logical AND | |
1598 | ||
1599 | @item || | |
1600 | logical OR | |
1601 | ||
1602 | @item = *= /= %= += -= <<= >>= &= ^= |= | |
1603 | assignment | |
1604 | @end table | |
1605 | ||
1606 | Shell variables are allowed as operands; parameter expansion is | |
1607 | performed before the expression is evaluated. | |
1608 | The value of a parameter is coerced to a long integer within | |
1609 | an expression. A shell variable need not have its integer attribute | |
1610 | turned on to be used in an expression. | |
1611 | ||
1612 | Constants with a leading 0 are interpreted as octal numbers. | |
1613 | A leading @code{0x} or @code{0X} denotes hexadecimal. Otherwise, | |
1614 | numbers take the form [@var{base#}]n, where @var{base} is a | |
1615 | decimal number between 2 and 36 representing the arithmetic | |
1616 | base, and @var{n} is a number in that base. If @var{base} is | |
1617 | omitted, then base 10 is used. | |
1618 | ||
1619 | Operators are evaluated in order of precedence. Sub-expressions in | |
1620 | parentheses are evaluated first and may override the precedence | |
1621 | rules above. | |
1622 | ||
1623 | @node Arithmetic Expansion | |
1624 | @subsection Arithmetic Expansion | |
1625 | ||
1626 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
1627 | and the substitution of the result. There are two formats for | |
1628 | arithmetic expansion: | |
1629 | ||
1630 | @example | |
1631 | $[ expression ] | |
1632 | $(( expression )) | |
1633 | @end example | |
1634 | ||
1635 | The expression is treated as if it were within double quotes, but | |
1636 | a double quote inside the braces or parentheses is not treated | |
1637 | specially. All tokens in the expression undergo parameter | |
1638 | expansion, command substitution, and quote removal. Arithmetic | |
1639 | substitutions may be nested. | |
1640 | ||
1641 | The evaluation is performed according to the rules listed above. | |
1642 | If the expression is invalid, Bash | |
1643 | prints a message indicating failure and no substitution occurs. | |
1644 | ||
1645 | @node Arithmetic Builtins | |
1646 | @subsection Arithmetic Builtins | |
1647 | ||
1648 | @ftable @code | |
1649 | @item let | |
1650 | @example | |
1651 | let @var{expression} [@var{expression}] | |
1652 | @end example | |
1653 | The @code{let} builtin allows arithmetic to be performed on shell | |
1654 | variables. Each @var{expression} is evaluated according to the | |
1655 | rules given previously (@pxref{Arithmetic Evaluation}). If the | |
1656 | last @var{expression} evaluates to 0, @code{let} returns 1; | |
1657 | otherwise 0 is returned. | |
1658 | @end ftable | |
1659 | ||
1660 | @node Printing a Prompt | |
1661 | @section Controlling the Prompt | |
1662 | ||
1663 | The value of the variable @code{$PROMPT_COMMAND} is examined just before | |
1664 | Bash prints each primary prompt. If it is set and non-null, then the | |
1665 | value is executed just as if you had typed it on the command line. | |
1666 | ||
1667 | In addition, the following table describes the special characters which | |
1668 | can appear in the @code{PS1} variable: | |
1669 | ||
1670 | @table @code | |
1671 | @item \t | |
1672 | the time, in HH:MM:SS format. | |
1673 | @item \d | |
1674 | the date, in "Weekday Month Date" format (e.g. "Tue May 26"). | |
1675 | @item \n | |
1676 | newline. | |
1677 | @item \s | |
1678 | the name of the shell, the basename of @code{$0} (the portion | |
1679 | following the final slash). | |
1680 | @item \w | |
1681 | the current working directory. | |
1682 | @item \W | |
1683 | the basename of @code{$PWD}. | |
1684 | @item \u | |
1685 | your username. | |
1686 | @item \h | |
1687 | the hostname. | |
1688 | @item \# | |
1689 | the command number of this command. | |
1690 | @item \! | |
1691 | the history number of this command. | |
1692 | @item \nnn | |
1693 | the character corresponding to the octal number @code{nnn}. | |
1694 | @item \$ | |
1695 | if the effective uid is 0, @code{#}, otherwise @code{$}. | |
1696 | @item \\ | |
1697 | a backslash. | |
1698 | @item \[ | |
1699 | begin a sequence of non-printing characters. This could be used to | |
1700 | embed a terminal control sequence into the prompt. | |
1701 | @item \] | |
1702 | end a sequence of non-printing characters. | |
1703 | @end table | |
1704 | ||
1705 | @node Job Control | |
1706 | @chapter Job Control | |
1707 | ||
1708 | This chapter disusses what job control is, how it works, and how | |
1709 | Bash allows you to access its facilities. | |
1710 | ||
1711 | @menu | |
1712 | * Job Control Basics:: How job control works. | |
1713 | * Job Control Builtins:: Bash builtin commands used to interact | |
1714 | with job control. | |
1715 | * Job Control Variables:: Variables Bash uses to customize job | |
1716 | control. | |
1717 | @end menu | |
1718 | ||
1719 | @node Job Control Basics | |
1720 | @section Job Control Basics | |
1721 | ||
1722 | Job control | |
1723 | refers to the ability to selectively stop (suspend) | |
1724 | the execution of processes and continue (resume) | |
1725 | their execution at a later point. A user typically employs | |
1726 | this facility via an interactive interface supplied jointly | |
1727 | by the system's terminal driver and Bash. | |
1728 | ||
1729 | The shell associates a @var{job} with each pipeline. It keeps a | |
1730 | table of currently executing jobs, which may be listed with the | |
1731 | @code{jobs} command. When Bash starts a job | |
1732 | asynchronously (in the background), it prints a line that looks | |
1733 | like: | |
1734 | @example | |
1735 | [1] 25647 | |
1736 | @end example | |
1737 | indicating that this job is job number 1 and that the process ID | |
1738 | of the last process in the pipeline associated with this job is | |
1739 | 25647. All of the processes in a single pipeline are members of | |
1740 | the same job. Bash uses the @var{job} abstraction as the | |
1741 | basis for job control. | |
1742 | ||
1743 | To facilitate the implementation of the user interface to job | |
1744 | control, the system maintains the notion of a current terminal | |
1745 | process group ID. Members of this process group (processes whose | |
1746 | process group ID is equal to the current terminal process group | |
1747 | ID) receive keyboard-generated signals such as @code{SIGINT}. | |
1748 | These processes are said to be in the foreground. Background | |
1749 | processes are those whose process group ID differs from the | |
1750 | terminal's; such processes are immune to keyboard-generated | |
1751 | signals. Only foreground processes are allowed to read from or | |
1752 | write to the terminal. Background processes which attempt to | |
1753 | read from (write to) the terminal are sent a @code{SIGTTIN} | |
1754 | (@code{SIGTTOU}) signal by the terminal driver, which, unless | |
1755 | caught, suspends the process. | |
1756 | ||
1757 | If the operating system on which Bash is running supports | |
1758 | job control, Bash allows you to use it. Typing the | |
1759 | @var{suspend} character (typically @samp{^Z}, Control-Z) while a | |
1760 | process is running causes that process to be stopped and returns | |
1761 | you to Bash. Typing the @var{delayed suspend} character | |
1762 | (typically @samp{^Y}, Control-Y) causes the process to be stopped | |
1763 | when it attempts to read input from the terminal, and control to | |
1764 | be returned to Bash. You may then manipulate the state of | |
1765 | this job, using the @code{bg} command to continue it in the | |
1766 | background, the @code{fg} command to continue it in the | |
1767 | foreground, or the @code{kill} command to kill it. A @samp{^Z} | |
1768 | takes effect immediately, and has the additional side effect of | |
1769 | causing pending output and typeahead to be discarded. | |
1770 | ||
1771 | There are a number of ways to refer to a job in the shell. The | |
1772 | character @samp{%} introduces a job name. Job number @code{n} | |
1773 | may be referred to as @samp{%n}. A job may also be referred to | |
1774 | using a prefix of the name used to start it, or using a substring | |
1775 | that appears in its command line. For example, @samp{%ce} refers | |
1776 | to a stopped @code{ce} job. Using @samp{%?ce}, on the | |
1777 | other hand, refers to any job containing the string @samp{ce} in | |
1778 | its command line. If the prefix or substring matches more than one job, | |
1779 | Bash reports an error. The symbols @samp{%%} and | |
1780 | @samp{%+} refer to the shell's notion of the current job, which | |
1781 | is the last job stopped while it was in the foreground. The | |
1782 | previous job may be referenced using @samp{%-}. In output | |
1783 | pertaining to jobs (e.g., the output of the @code{jobs} command), | |
1784 | the current job is always flagged with a @samp{+}, and the | |
1785 | previous job with a @samp{-}. | |
1786 | ||
1787 | Simply naming a job can be used to bring it into the foreground: | |
1788 | @samp{%1} is a synonym for @samp{fg %1} bringing job 1 from the | |
1789 | background into the foreground. Similarly, @samp{%1 &} resumes | |
1790 | job 1 in the background, equivalent to @samp{bg %1} | |
1791 | ||
1792 | The shell learns immediately whenever a job changes state. | |
1793 | Normally, Bash waits until it is about to print a prompt | |
1794 | before reporting changes in a job's status so as to not interrupt | |
1795 | any other output. If the | |
1796 | the @code{-b} option to the @code{set} builtin is set, | |
1797 | Bash reports such changes immediately (@pxref{The Set Builtin}). | |
1798 | This feature is also controlled by the variable @code{notify}. | |
1799 | ||
1800 | If you attempt to exit bash while jobs are stopped, the | |
1801 | shell prints a message warning you. You may then use the | |
1802 | @code{jobs} command to inspect their status. If you do this, or | |
1803 | try to exit again immediately, you are not warned again, and the | |
1804 | stopped jobs are terminated. | |
1805 | ||
1806 | @node Job Control Builtins | |
1807 | @section Job Control Builtins | |
1808 | ||
1809 | @ftable @code | |
1810 | ||
1811 | @item bg | |
1812 | @example | |
1813 | bg [@var{jobspec}] | |
1814 | @end example | |
1815 | Place @var{jobspec} into the background, as if it had been started | |
1816 | with @samp{&}. If @var{jobspec} is not supplied, the current job | |
1817 | is used. | |
1818 | ||
1819 | @item fg | |
1820 | @example | |
1821 | fg [@var{jobspec}] | |
1822 | @end example | |
1823 | Bring @var{jobspec} into the foreground and make it the current job. | |
1824 | If @var{jobspec} is not supplied, the current job is used. | |
1825 | ||
1826 | @item jobs | |
1827 | @example | |
1828 | jobs [-lpn] [@var{jobspec}] | |
1829 | jobs -x @var{command} [@var{jobspec}] | |
1830 | @end example | |
1831 | ||
1832 | The first form lists the active jobs. The @code{-l} option lists | |
1833 | process IDs in addition to the normal information; the @code{-p} | |
1834 | option lists only the process ID of the job's process group | |
1835 | leader. The @code{-n} option displays only jobs that have | |
1836 | changed status since last notfied. If @var{jobspec} is given, | |
1837 | output is restricted to information about that job. | |
1838 | If @var{jobspec} is not supplied, the status of all jobs is | |
1839 | listed. | |
1840 | ||
1841 | If the @code{-x} option is supplied, @code{jobs} replaces any | |
1842 | @var{jobspec} found in @var{command} or @var{arguments} with the | |
1843 | corresponding process group ID, and executes @var{command}, | |
1844 | passing it @var{argument}s, returning its exit status. | |
1845 | ||
1846 | @item suspend | |
1847 | @example | |
1848 | suspend [-f] | |
1849 | @end example | |
1850 | Suspend the execution of this shell until it receives a | |
1851 | @code{SIGCONT} signal. The @code{-f} option means to suspend | |
1852 | even if the shell is a login shell. | |
1853 | ||
1854 | @end ftable | |
1855 | ||
1856 | When job control is active, the @code{kill} and @code{wait} | |
1857 | builtins also accept @var{jobspec} arguments. | |
1858 | ||
1859 | @node Job Control Variables | |
1860 | @section Job Control Variables | |
1861 | ||
1862 | @vtable @code | |
1863 | ||
1864 | @item auto_resume | |
1865 | This variable controls how the shell interacts with the user and | |
1866 | job control. If this variable exists then single word simple | |
1867 | commands without redirects are treated as candidates for resumption | |
1868 | of an existing job. There is no ambiguity allowed; if you have | |
1869 | more than one job beginning with the string that you have typed, then | |
1870 | the most recently accessed job will be selected. | |
1871 | The name of a stopped job, in this context, is the command line | |
1872 | used to start it. If this variable is set to the value @code{exact}, | |
1873 | the string supplied must match the name of a stopped job exactly; | |
1874 | if set to @code{substring}, | |
1875 | the string supplied needs to match a substring of the name of a | |
1876 | stopped job. The @code{substring} value provides functionality | |
1877 | analogous to the @code{%?} job id (@pxref{Job Control Basics}). | |
1878 | If set to any other value, the supplied string must | |
1879 | be a prefix of a stopped job's name; this provides functionality | |
1880 | analogous to the @code{%} job id. | |
1881 | ||
1882 | @item notify | |
1883 | Setting this variable to a value is equivalent to | |
1884 | @samp{set -b}; unsetting it is equivalent to @samp{set +b} | |
1885 | (@pxref{The Set Builtin}). | |
1886 | ||
1887 | @end vtable | |
1888 | ||
1889 | @set readline-appendix | |
1890 | @set history-appendix | |
1891 | @cindex History, how to use | |
1892 | @include hsuser.texinfo | |
1893 | @cindex Readline, how to use | |
1894 | @include rluser.texinfo | |
1895 | @clear readline-appendix | |
1896 | @clear history-appendix | |
1897 | ||
1898 | @node Variable Index | |
1899 | @appendix Variable Index | |
1900 | @printindex vr | |
1901 | ||
1902 | @node Concept Index | |
1903 | @appendix Concept Index | |
1904 | @printindex cp | |
1905 | ||
1906 | @contents | |
1907 | @bye |