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