Bash-4.2 distribution sources and documentation
[platform/upstream/bash.git] / doc / FAQ
1 This is the Bash FAQ, version 4.12, for Bash version 4.2.
2
3 This document contains a set of frequently-asked questions concerning
4 Bash, the GNU Bourne-Again Shell.  Bash is a freely-available command
5 interpreter with advanced features for both interactive use and shell
6 programming.
7
8 Another good source of basic information about shells is the collection
9 of FAQ articles periodically posted to comp.unix.shell.
10
11 Questions and comments concerning this document should be sent to
12 chet.ramey@case.edu.
13
14 This document is available for anonymous FTP with the URL
15
16 ftp://ftp.cwru.edu/pub/bash/FAQ
17
18 The Bash home page is http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html
19
20 ----------
21 Contents:
22
23 Section A:  The Basics
24
25 A1) What is it?
26 A2) What's the latest version?
27 A3) Where can I get it?
28 A4) On what machines will bash run?
29 A5) Will bash run on operating systems other than Unix?
30 A6) How can I build bash with gcc?
31 A7) How can I make bash my login shell?
32 A8) I just changed my login shell to bash, and now I can't FTP into my
33     machine.  Why not?
34 A9) What's the `POSIX Shell and Utilities standard'?
35 A10) What is the bash `posix mode'?
36
37 Section B:  The latest version
38
39 B1) What's new in version 4.2?
40 B2) Are there any user-visible incompatibilities between bash-4.2 and
41     previous bash versions?
42
43 Section C:  Differences from other Unix shells
44
45 C1) How does bash differ from sh, the Bourne shell?
46 C2) How does bash differ from the Korn shell, version ksh88?
47 C3) Which new features in ksh-93 are not in bash, and which are?
48
49 Section D:  Why does bash do some things differently than other Unix shells?
50
51 D1) Why does bash run a different version of `command' than
52     `which command' says it will?
53 D2) Why doesn't bash treat brace expansions exactly like csh?
54 D3) Why doesn't bash have csh variable modifiers?
55 D4) How can I make my csh aliases work when I convert to bash?
56 D5) How can I pipe standard output and standard error from one command to
57     another, like csh does with `|&'?
58 D6) Now that I've converted from ksh to bash, are there equivalents to
59     ksh features like autoloaded functions and the `whence' command?
60
61 Section E:  Why does bash do certain things the way it does?
62
63 E1) Why is the bash builtin `test' slightly different from /bin/test?
64 E2) Why does bash sometimes say `Broken pipe'?
65 E3) When I have terminal escape sequences in my prompt, why does bash
66     wrap lines at the wrong column?
67 E4) If I pipe the output of a command into `read variable', why doesn't
68     the output show up in $variable when the read command finishes?
69 E5) I have a bunch of shell scripts that use backslash-escaped characters
70     in arguments to `echo'.  Bash doesn't interpret these characters.  Why
71     not, and how can I make it understand them?
72 E6) Why doesn't a while or for loop get suspended when I type ^Z?
73 E7) What about empty for loops in Makefiles?
74 E8) Why does the arithmetic evaluation code complain about `08'?
75 E9) Why does the pattern matching expression [A-Z]* match files beginning
76     with every letter except `z'?
77 E10) Why does `cd //' leave $PWD as `//'?
78 E11) If I resize my xterm while another program is running, why doesn't bash
79      notice the change?
80 E12) Why don't negative offsets in substring expansion work like I expect?
81 E13) Why does filename completion misbehave if a colon appears in the filename?
82 E14) Why does quoting the pattern argument to the regular expression matching
83      conditional operator (=~) cause matching to stop working?
84 E15) Tell me more about the shell compatibility level.
85
86 Section F:  Things to watch out for on certain Unix versions
87
88 F1) Why can't I use command line editing in my `cmdtool'?
89 F2) I built bash on Solaris 2.  Why do globbing expansions and filename
90     completion chop off the first few characters of each filename?
91 F3) Why does bash dump core after I interrupt username completion or
92     `~user' tilde expansion on a machine running NIS?
93 F4) I'm running SVR4.2.  Why is the line erased every time I type `@'?
94 F5) Why does bash report syntax errors when my C News scripts use a
95     redirection before a subshell command?
96 F6) Why can't I use vi-mode editing on Red Hat Linux 6.1?
97 F7) Why do bash-2.05a and  bash-2.05b fail to compile `printf.def' on
98     HP/UX 11.x?
99
100 Section G:  How can I get bash to do certain common things?
101
102 G1) How can I get bash to read and display eight-bit characters?
103 G2) How do I write a function `x' to replace builtin command `x', but
104     still invoke the command from within the function?
105 G3) How can I find the value of a shell variable whose name is the value
106     of another shell variable?
107 G4) How can I make the bash `time' reserved word print timing output that
108     looks like the output from my system's /usr/bin/time?
109 G5) How do I get the current directory into my prompt?
110 G6) How can I rename "*.foo" to "*.bar"?
111 G7) How can I translate a filename from uppercase to lowercase?
112 G8) How can I write a filename expansion (globbing) pattern that will match
113     all files in the current directory except "." and ".."?
114
115 Section H:  Where do I go from here?
116
117 H1) How do I report bugs in bash, and where should I look for fixes and
118     advice?
119 H2) What kind of bash documentation is there?
120 H3) What's coming in future versions?
121 H4) What's on the bash `wish list'?
122 H5) When will the next release appear?
123
124 ----------
125 Section A:  The Basics
126
127 A1)  What is it?
128
129 Bash is a Unix command interpreter (shell).  It is an implementation of
130 the Posix 1003.2 shell standard, and resembles the Korn and System V
131 shells.
132
133 Bash contains a number of enhancements over those shells, both
134 for interactive use and shell programming.  Features geared
135 toward interactive use include command line editing, command
136 history, job control, aliases, and prompt expansion.  Programming
137 features include additional variable expansions, shell
138 arithmetic, and a number of variables and options to control
139 shell behavior.
140
141 Bash was originally written by Brian Fox of the Free Software
142 Foundation.  The current developer and maintainer is Chet Ramey
143 of Case Western Reserve University.
144
145 A2)  What's the latest version?
146
147 The latest version is 4.2, first made available on 14 February, 2011.
148
149 A3)  Where can I get it?
150
151 Bash is the GNU project's shell, and so is available from the
152 master GNU archive site, ftp.gnu.org, and its mirrors.  The
153 latest version is also available for FTP from ftp.cwru.edu.
154 The following URLs tell how to get version 4.2:
155
156 ftp://ftp.gnu.org/pub/gnu/bash/bash-4.2.tar.gz
157 ftp://ftp.cwru.edu/pub/bash/bash-4.2.tar.gz
158
159 Formatted versions of the documentation are available with the URLs:
160
161 ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-4.2.tar.gz
162 ftp://ftp.cwru.edu/pub/bash/bash-doc-4.2.tar.gz
163
164 Any patches for the current version are available with the URL:
165
166 ftp://ftp.cwru.edu/pub/bash/bash-4.2-patches/
167
168 A4)  On what machines will bash run?
169
170 Bash has been ported to nearly every version of Unix.  All you
171 should have to do to build it on a machine for which a port
172 exists is to type `configure' and then `make'.  The build process
173 will attempt to discover the version of Unix you have and tailor
174 itself accordingly, using a script created by GNU autoconf.
175
176 More information appears in the file `INSTALL' in the distribution.
177
178 The Bash web page (http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html)
179 explains how to obtain binary versions of bash for most of the major
180 commercial Unix systems.
181
182 A5) Will bash run on operating systems other than Unix?
183
184 Configuration specifics for Unix-like systems such as QNX and
185 LynxOS are included in the distribution.  Bash-2.05 and later
186 versions should compile and run on Minix 2.0 (patches were
187 contributed), but I don't believe anyone has built bash-2.x on
188 earlier Minix versions yet. 
189
190 Bash has been ported to versions of Windows implementing the Win32
191 programming interface.  This includes Windows 95 and Windows NT.
192 The port was done by Cygnus Solutions (now part of Red Hat) as part
193 of their CYGWIN project.  For more information about the project, see
194 http://www.cygwin.com/.
195
196 Cygnus originally ported bash-1.14.7, and that port was part of their
197 early GNU-Win32 (the original name) releases.  Cygnus has also done
198 ports of bash-3.2 and bash-4.0 to the CYGWIN environment, and both
199 are available as part of their current release.
200
201 Bash-2.05b and later versions should require no local Cygnus changes to
202 build and run under CYGWIN.
203
204 DJ Delorie has a port of bash-2.x which runs under MS-DOS, as part
205 of the DJGPP project.  For more information on the project, see
206
207 http://www.delorie.com/djgpp/
208
209 I have been told that the original DJGPP port was done by Daisuke Aoyama.
210
211 Mark Elbrecht <snowball3@bigfoot.com> has sent me notice that bash-2.04
212 is available for DJGPP V2.  The files are available as:
213
214 ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204b.zip  binary
215 ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204d.zip  documentation
216 ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204s.zip  source
217
218 Mark began to work with bash-2.05, but I don't know the current status.
219
220 Bash-3.0 compiles and runs with no modifications under Microsoft's Services
221 for Unix (SFU), once known as Interix.  I do not anticipate any problems
222 with building bash-4.2, but will gladly accept any patches that are needed.
223
224 A6) How can I build bash with gcc? 
225
226 Bash configures to use gcc by default if it is available.  Read the
227 file INSTALL in the distribution for more information.
228
229 A7)  How can I make bash my login shell?
230
231 Some machines let you use `chsh' to change your login shell.  Other
232 systems use `passwd -s' or `passwd -e'.  If one of these works for
233 you, that's all you need.  Note that many systems require the full
234 pathname to a shell to appear in /etc/shells before you can make it
235 your login shell.  For this, you may need the assistance of your
236 friendly local system administrator. 
237
238 If you cannot do this, you can still use bash as your login shell, but
239 you need to perform some tricks.  The basic idea is to add a command
240 to your login shell's startup file to replace your login shell with
241 bash.
242
243 For example, if your login shell is csh or tcsh, and you have installed
244 bash in /usr/gnu/bin/bash, add the following line to ~/.login:
245
246         if ( -f /usr/gnu/bin/bash ) exec /usr/gnu/bin/bash --login
247
248 (the `--login' tells bash that it is a login shell).
249
250 It's not a good idea to put this command into ~/.cshrc, because every
251 csh you run without the `-f' option, even ones started to run csh scripts,
252 reads that file.  If you must put the command in ~/.cshrc, use something
253 like
254
255         if ( $?prompt ) exec /usr/gnu/bin/bash --login
256
257 to ensure that bash is exec'd only when the csh is interactive.
258
259 If your login shell is sh or ksh, you have to do two things.
260
261 First, create an empty file in your home directory named `.bash_profile'.
262 The existence of this file will prevent the exec'd bash from trying to
263 read ~/.profile, and re-execing itself over and over again.  ~/.bash_profile
264 is the first file bash tries to read initialization commands from when
265 it is invoked as a login shell.
266
267 Next, add a line similar to the above to ~/.profile:
268
269         [ -f /usr/gnu/bin/bash ] && [ -x /usr/gnu/bin/bash ] && \
270                 exec /usr/gnu/bin/bash --login
271
272 This will cause login shells to replace themselves with bash running as
273 a login shell.  Once you have this working, you can copy your initialization
274 code from ~/.profile to ~/.bash_profile.
275
276 I have received word that the recipe supplied above is insufficient for
277 machines running CDE.  CDE has a maze of twisty little startup files, all
278 slightly different.
279
280 If you cannot change your login shell in the password file to bash, you
281 will have to (apparently) live with CDE using the shell in the password
282 file to run its startup scripts.  If you have changed your shell to bash,
283 there is code in the CDE startup files (on Solaris, at least) that attempts
284 to do the right thing.  It is, however, often broken, and may require that
285 you use the $BASH_ENV trick described below.
286
287 `dtterm' claims to use $SHELL as the default program to start, so if you
288 can change $SHELL in the CDE startup files, you should be able to use bash
289 in your terminal windows.
290
291 Setting DTSOURCEPROFILE in ~/.dtprofile will cause the `Xsession' program
292 to read your login shell's startup files.  You may be able to use bash for
293 the rest of the CDE programs by setting SHELL to bash in ~/.dtprofile as
294 well, but I have not tried this.
295
296 You can use the above `exec' recipe to start bash when not logging in with
297 CDE by testing the value of the DT variable:
298
299         if [ -n "$DT" ]; then
300                 [ -f /usr/gnu/bin/bash ] && exec /usr/gnu/bin/bash --login
301         fi
302
303 If CDE starts its shells non-interactively during login, the login shell
304 startup files (~/.profile, ~/.bash_profile) will not be sourced at login.
305 To get around this problem, append a line similar to the following to your
306 ~/.dtprofile:
307
308         BASH_ENV=${HOME}/.bash_profile ; export BASH_ENV
309
310 and add the following line to the beginning of ~/.bash_profile:
311
312         unset BASH_ENV
313
314 A8) I just changed my login shell to bash, and now I can't FTP into my
315    machine.  Why not?
316
317 You must add the full pathname to bash to the file /etc/shells.  As
318 noted in the answer to the previous question, many systems require
319 this before you can make bash your login shell. 
320
321 Most versions of ftpd use this file to prohibit `special' users
322 such as `uucp' and `news' from using FTP. 
323
324 A9)  What's the `POSIX Shell and Utilities standard'?
325
326 POSIX is a name originally coined by Richard Stallman for a
327 family of open system standards based on UNIX.  There are a
328 number of aspects of UNIX under consideration for
329 standardization, from the basic system services at the system
330 call and C library level to applications and tools to system
331 administration and management.  Each area of standardization is
332 assigned to a working group in the 1003 series. 
333
334 The POSIX Shell and Utilities standard was originally developed by
335 IEEE Working Group 1003.2 (POSIX.2).  Today it has been merged with
336 the original 1003.1 Working Group and is maintained by the Austin
337 Group (a joint working group of the IEEE, The Open Group and
338 ISO/IEC SC22/WG15).  Today the Shell and Utilities are a volume
339 within the set of documents that make up IEEE Std 1003.1-2001, and
340 thus now the former POSIX.2 (from 1992) is now part of the current
341 POSIX.1 standard (POSIX 1003.1-2001). 
342
343 The Shell and Utilities volume concentrates on the command
344 interpreter interface and utility programs commonly executed from
345 the command line or by other programs.  The standard is freely
346 available on the web at http://www.UNIX-systems.org/version3/ . 
347 Work continues at the Austin Group on maintenance issues; see
348 http://www.opengroup.org/austin/ to join the discussions. 
349
350 Bash is concerned with the aspects of the shell's behavior defined
351 by the POSIX Shell and Utilities volume.  The shell command
352 language has of course been standardized, including the basic flow
353 control and program execution constructs, I/O redirection and
354 pipelining, argument handling, variable expansion, and quoting. 
355
356 The `special' builtins, which must be implemented as part of the
357 shell to provide the desired functionality, are specified as
358 being part of the shell; examples of these are `eval' and
359 `export'.  Other utilities appear in the sections of POSIX not
360 devoted to the shell which are commonly (and in some cases must
361 be) implemented as builtin commands, such as `read' and `test'. 
362 POSIX also specifies aspects of the shell's interactive
363 behavior as part of the UPE, including job control and command
364 line editing.  Only vi-style line editing commands have been
365 standardized; emacs editing commands were left out due to
366 objections.
367
368 The latest version of the POSIX Shell and Utilities standard is
369 available (now updated to the 2004 Edition) as part of the Single
370 UNIX Specification Version 3 at
371
372 http://www.UNIX-systems.org/version3/
373
374 A10)  What is the bash `posix mode'?
375
376 Although bash is an implementation of the POSIX shell
377 specification, there are areas where the bash default behavior
378 differs from that spec.  The bash `posix mode' changes the bash
379 behavior in these areas so that it obeys the spec more closely. 
380
381 Posix mode is entered by starting bash with the --posix or
382 '-o posix' option or executing `set -o posix' after bash is running.
383
384 The specific aspects of bash which change when posix mode is
385 active are listed in the file POSIX in the bash distribution.
386 They are also listed in a section in the Bash Reference Manual
387 (from which that file is generated).
388
389 Section B:  The latest version
390
391 B1) What's new in version 4.2?
392
393 Bash-4.2 is the second revision to the fourth major release of bash.
394
395 Bash-4.2 contains the following new features (see the manual page for
396 complete descriptions and the CHANGES and NEWS files in the bash-4.2
397 distribution):
398
399 o   `exec -a foo' now sets $0 to `foo' in an executable shell script without a
400     leading #!.
401
402 o   Subshells begun to execute command substitutions or run shell functions or
403     builtins in subshells do not reset trap strings until a new trap is
404     specified.  This allows $(trap) to display the caller's traps and the
405     trap strings to persist until a new trap is set.
406
407 o   `trap -p' will now show signals ignored at shell startup, though their
408     disposition still cannot be modified.
409
410 o   $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
411
412 o   declare/typeset has a new `-g' option, which creates variables in the
413     global scope even when run in a shell function.
414
415 o   test/[/[[ have a new -v variable unary operator, which returns success if
416     `variable' has been set.
417
418 o   Posix parsing changes to allow `! time command' and multiple consecutive
419     instances of `!' (which toggle) and `time' (which have no cumulative
420     effect).
421
422 o   Posix change to allow `time' as a command by itself to print the elapsed
423     user, system, and real times for the shell and its children.
424
425 o   $((...)) is always parsed as an arithmetic expansion first, instead of as
426     a potential nested command substitution, as Posix requires.
427
428 o   A new FUNCNEST variable to allow the user to control the maximum shell
429     function nesting (recursive execution) level.
430
431 o   The mapfile builtin now supplies a third argument to the callback command:
432     the line about to be assigned to the supplied array index.
433
434 o   The printf builtin has as new %(fmt)T specifier, which allows time values
435     to use strftime-like formatting.
436
437 o   There is a new `compat41' shell option.
438
439 o   The cd builtin has a new Posix-mandated `-e' option.
440
441 o   Negative subscripts to indexed arrays, previously errors, now are treated
442     as offsets from the maximum assigned index + 1.
443
444 o   Negative length specifications in the ${var:offset:length} expansion,
445     previously errors, are now treated as offsets from the end of the variable.
446
447 o   Parsing change to allow `time -p --'.
448
449 o   Posix-mode parsing change to not recognize `time' as a keyword if the
450     following token begins with a `-'.  This means no more Posix-mode
451     `time -p'.  Posix interpretation 267.
452
453 o   There is a new `lastpipe' shell option that runs the last command of a
454     pipeline in the current shell context.  The lastpipe option has no
455     effect if job control is enabled.
456
457 o   History expansion no longer expands the `$!' variable expansion.
458
459 o   Posix mode shells no longer exit if a variable assignment error occurs
460     with an assignment preceding a command that is not a special builtin.
461
462 o   Non-interactive mode shells exit if -u is enabled an an attempt is made
463     to use an unset variable with the % or # expansions, the `//', `^', or
464     `,' expansions, or the parameter length expansion.
465
466 o   Posix-mode shells use the argument passed to `.' as-is if a $PATH search
467     fails, effectively searching the current directory.  Posix-2008 change.
468
469 A short feature history dating back to Bash-2.0:
470
471 Bash-4.1 contained the following new features:
472
473 o   Here-documents within $(...) command substitutions may once more be
474     delimited by the closing right paren, instead of requiring a newline.
475
476 o   Bash's file status checks (executable, readable, etc.) now take file
477     system ACLs into account on file systems that support them.
478
479 o   Bash now passes environment variables with names that are not valid
480     shell variable names through into the environment passed to child
481     processes.
482
483 o   The `execute-unix-command' readline function now attempts to clear and
484     reuse the current line rather than move to a new one after the command
485     executes.
486
487 o   `printf -v' can now assign values to array indices.
488
489 o   New `complete -E' and `compopt -E' options that work on the "empty"
490     completion: completion attempted on an empty command line.
491
492 o   New complete/compgen/compopt -D option to define a `default' completion:
493     a completion to be invoked on command for which no completion has been
494     defined.  If this function returns 124, programmable completion is
495     attempted again, allowing a user to dynamically build a set of completions
496     as completion is attempted by having the default completion function
497     install individual completion functions each time it is invoked.
498
499 o   When displaying associative arrays, subscripts are now quoted.
500
501 o   Changes to dabbrev-expand to make it more `emacs-like': no space appended
502     after matches, completions are not sorted, and most recent history entries
503     are presented first.
504
505 o   The [[ and (( commands are now subject to the setting of `set -e' and the
506     ERR trap.
507
508 o   The source/. builtin now removes NUL bytes from the file before attempting
509     to parse commands.
510
511 o   There is a new configuration option (in config-top.h) that forces bash to
512     forward all history entries to syslog.
513
514 o   A new variable $BASHOPTS to export shell options settable using `shopt' to
515     child processes.
516
517 o   There is a new confgure option that forces the extglob option to be
518     enabled by default.
519
520 o   New variable $BASH_XTRACEFD; when set to an integer bash will write xtrace
521     output to that file descriptor.
522
523 o   If the optional left-hand-side of a redirection is of the form {var}, the
524     shell assigns the file descriptor used to $var or uses $var as the file
525     descriptor to move or close, depending on the redirection operator.
526
527 o   The < and > operators to the [[ conditional command now do string
528     comparison according to the current locale.
529
530 o   Programmable completion now uses the completion for `b' instead of `a'
531     when completion is attempted on a line like: a $(b c.
532
533 o   Force extglob on temporarily when parsing the pattern argument to
534     the == and != operators to the [[ command, for compatibility.
535
536 o   Changed the behavior of interrupting the wait builtin when a SIGCHLD is
537     received and a trap on SIGCHLD is set to be Posix-mode only.
538
539 o   The read builtin has a new `-N nchars' option, which reads exactly NCHARS
540     characters, ignoring delimiters like newline.
541
542 o   The mapfile/readarray builtin no longer stores the commands it invokes via
543     callbacks in the history list.
544
545 o   There is a new `compat40' shopt option.
546
547 o   The < and > operators to [[ do string comparisons using the current locale
548     only if the compatibility level is greater than 40 (set to 41 by default).
549
550 o   New bindable readline function: menu-complete-backward.
551
552 o   In the readline vi-mode insertion keymap, C-n is now bound to menu-complete
553     by default, and C-p to menu-complete-backward.
554
555 o   When in readline vi command mode, repeatedly hitting ESC now does nothing,
556     even when ESC introduces a bound key sequence.  This is closer to how
557     historical vi behaves.
558
559 o   New bindable readline function: skip-csi-sequence.  Can be used as a
560     default to consume key sequences generated by keys like Home and End
561     without having to bind all keys.
562
563 o   New bindable readline variable: skip-completed-text, active when
564     completing in the middle of a word.  If enabled, it means that characters
565     in the completion that match characters in the remainder of the word are
566     "skipped" rather than inserted into the line.
567
568 o   The pre-readline-6.0 version of menu completion is available as
569     "old-menu-complete" for users who do not like the readline-6.0 version.
570
571 o   New bindable readline variable: echo-control-characters.  If enabled, and
572     the tty ECHOCTL bit is set, controls the echoing of characters
573     corresponding to keyboard-generated signals.
574
575 o   New bindable readline variable: enable-meta-key.  Controls whether or not
576     readline sends the smm/rmm sequences if the terminal indicates it has a
577     meta key that enables eight-bit characters.
578
579 Bash-4.0 contained the following new features:
580
581 o   When using substring expansion on the positional parameters, a starting
582     index of 0 now causes $0 to be prefixed to the list.
583
584 o   There is a new variable, $BASHPID, which always returns the process id of
585     the current shell.
586
587 o   There is a new `autocd' option that, when enabled, causes bash to attempt
588     to `cd' to a directory name that is supplied as the first word of a
589     simple command.
590
591 o   There is a new `checkjobs' option that causes the shell to check for and
592     report any running or stopped jobs at exit.
593
594 o   The programmable completion code exports a new COMP_TYPE variable, set to
595     a character describing the type of completion being attempted.
596
597 o   The programmable completion code exports a new COMP_KEY variable, set to
598     the character that caused the completion to be invoked (e.g., TAB).
599
600 o   The programmable completion code now uses the same set of characters as
601     readline when breaking the command line into a list of words.
602
603 o   The block multiplier for the ulimit -c and -f options is now 512 when in
604     Posix mode, as Posix specifies.
605
606 o   Changed the behavior of the read builtin to save any partial input received
607     in the specified variable when the read builtin times out.  This also
608     results in variables specified as arguments to read to be set to the empty
609     string when there is no input available.  When the read builtin times out,
610     it returns an exit status greater than 128.
611
612 o   The shell now has the notion of a `compatibility level', controlled by
613     new variables settable by `shopt'.  Setting this variable currently
614     restores the bash-3.1 behavior when processing quoted strings on the rhs
615     of the `=~' operator to the `[[' command.
616
617 o   The `ulimit' builtin now has new -b (socket buffer size) and -T (number
618     of threads) options.
619
620 o   There is a new `compopt' builtin that allows completion functions to modify
621     completion options for existing completions or the completion currently
622     being executed.
623
624 o   The `read' builtin has a new -i option which inserts text into the reply
625     buffer when using readline.
626
627 o   A new `-E' option to the complete builtin allows control of the default
628     behavior for completion on an empty line.
629
630 o   There is now limited support for completing command name words containing
631     globbing characters.
632
633 o   The `help' builtin now has a new -d option, to display a short description,
634     and a -m option, to print help information in a man page-like format.
635
636 o   There is a new `mapfile' builtin to populate an array with lines from a
637     given file.
638
639 o   If a command is not found, the shell attempts to execute a shell function
640     named `command_not_found_handle', supplying the command words as the
641     function arguments.
642
643 o   There is a new shell option: `globstar'.  When enabled, the globbing code
644     treats `**' specially -- it matches all directories (and files within
645     them, when appropriate) recursively.
646
647 o   There is a new shell option: `dirspell'.  When enabled, the filename
648     completion code performs spelling correction on directory names during
649     completion.
650
651 o   The `-t' option to the `read' builtin now supports fractional timeout
652     values.
653
654 o   Brace expansion now allows zero-padding of expanded numeric values and
655     will add the proper number of zeroes to make sure all values contain the
656     same number of digits.
657
658 o   There is a new bash-specific bindable readline function: `dabbrev-expand'.
659     It uses menu completion on a set of words taken from the history list.
660
661 o   The command assigned to a key sequence with `bind -x' now sets two new
662     variables in the environment of the executed command:  READLINE_LINE_BUFFER
663     and READLINE_POINT.  The command can change the current readline line
664     and cursor position by modifying READLINE_LINE_BUFFER and READLINE_POINT,
665     respectively.
666
667 o   There is a new >>& redirection operator, which appends the standard output
668     and standard error to the named file.
669
670 o   The parser now understands `|&' as a synonym for `2>&1 |', which redirects
671     the standard error for a command through a pipe.
672
673 o   The new `;&' case statement action list terminator causes execution to
674     continue with the action associated with the next pattern in the
675     statement rather than terminating the command.
676
677 o   The new `;;&' case statement action list terminator causes the shell to
678     test the next set of patterns after completing execution of the current
679     action, rather than terminating the command.
680
681 o   The shell understands a new variable: PROMPT_DIRTRIM.  When set to an
682     integer value greater than zero, prompt expansion of \w and \W  will
683     retain only that number of trailing pathname components and replace
684     the intervening characters with `...'.
685
686 o   There are new case-modifying word expansions: uppercase (^[^]) and
687     lowercase (,[,]).  They can work on either the first character or
688     array element, or globally.  They accept an optional shell pattern
689     that determines which characters to modify.  There is an optionally-
690     configured feature to include capitalization operators.
691
692 o   The shell provides associative array variables, with the appropriate
693     support to create, delete, assign values to, and expand them.
694
695 o   The `declare' builtin now has new -l (convert value to lowercase upon
696     assignment) and -u (convert value to uppercase upon assignment) options.
697     There is an optionally-configurable -c option to capitalize a value at
698     assignment.
699
700 o   There is a new `coproc' reserved word that specifies a coprocess: an
701     asynchronous command run with two pipes connected to the creating shell.
702     Coprocs can be named.  The input and output file descriptors and the
703     PID of the coprocess are available to the calling shell in variables
704     with coproc-specific names.
705
706 o   A value of 0 for the -t option to `read' now returns success if there is
707     input available to be read from the specified file descriptor.
708
709 o   CDPATH and GLOBIGNORE are ignored when the shell is running in privileged
710     mode.
711
712 o   New bindable readline functions shell-forward-word and shell-backward-word,
713     which move forward and backward words delimited by shell metacharacters
714     and honor shell quoting.
715
716 o   New bindable readline functions shell-backward-kill-word and shell-kill-word
717     which kill words backward and forward, but use the same word boundaries
718     as shell-forward-word and shell-backward-word.
719
720 Bash-3.2 contained the following new features:
721
722 o Bash-3.2 now checks shell scripts for NUL characters rather than non-printing
723   characters when deciding whether or not a script is a binary file.
724
725 o Quoting the string argument to the [[ command's  =~ (regexp) operator now
726   forces string matching, as with the other pattern-matching operators.
727
728 Bash-3.1 contained the following new features:
729
730 o Bash-3.1 may now be configured and built in a mode that enforces strict
731   POSIX compliance.
732
733 o The `+=' assignment operator, which appends to the value of a string or
734   array variable, has been implemented.
735
736 o It is now possible to ignore case when matching in contexts other than
737   filename generation using the new `nocasematch' shell option.
738
739 Bash-3.0 contained the following new features:
740
741 o Features to support the bash debugger have been implemented, and there
742   is a new `extdebug' option to turn the non-default options on
743
744 o HISTCONTROL is now a colon-separated list of options and has been
745   extended with a new `erasedups' option that will result in only one
746   copy of a command being kept in the history list
747
748 o Brace expansion has been extended with a new {x..y} form, producing
749   sequences of digits or characters
750
751 o Timestamps are now kept with history entries, with an option to save
752   and restore them from the history file; there is a new HISTTIMEFORMAT
753   variable describing how to display the timestamps when listing history
754   entries
755
756 o The `[[' command can now perform extended regular expression (egrep-like)
757   matching, with matched subexpressions placed in the BASH_REMATCH array
758   variable
759
760 o A new `pipefail' option causes a pipeline to return a failure status if
761   any command in it fails
762
763 o The `jobs', `kill', and `wait' builtins now accept job control notation
764   in their arguments even if job control is not enabled
765
766 o The `gettext' package and libintl have been integrated, and the shell
767   messages may be translated into other languages
768
769 Bash-2.05b introduced the following new features:
770
771 o support for multibyte characters has been added to both bash and readline
772
773 o the DEBUG trap is now run *before* simple commands, ((...)) commands,
774   [[...]] conditional commands, and for ((...)) loops
775
776 o the shell now performs arithmetic in the largest integer size the machine
777   supports (intmax_t)
778
779 o there is a new \D{...} prompt expansion; passes the `...' to strftime(3)
780   and inserts the result into the expanded prompt
781
782 o there is a new `here-string' redirection operator:  <<< word
783
784 o when displaying variables, function attributes and definitions are shown
785   separately, allowing them to be re-used as input (attempting to re-use
786   the old output would result in syntax errors).
787
788 o `read' has a new `-u fd' option to read from a specified file descriptor
789
790 o the bash debugger in examples/bashdb has been modified to work with the
791   new DEBUG trap semantics, the command set has been made more gdb-like,
792   and the changes to $LINENO make debugging functions work better
793
794 o the expansion of $LINENO inside a shell function is only relative to the
795   function start if the shell is interactive -- if the shell is running a
796   script, $LINENO expands to the line number in the script.  This is as
797   POSIX-2001 requires
798
799 Bash-2.05a introduced the following new features:
800
801 o The `printf' builtin has undergone major work
802
803 o There is a new read-only `shopt' option: login_shell, which is set by
804   login shells and unset otherwise
805
806 o New `\A' prompt string escape sequence; expanding to time in 24-hour
807   HH:MM format
808
809 o New `-A group/-g' option to complete and compgen; goes group name
810   completion
811
812 o New [+-]O invocation option to set and unset `shopt' options at startup
813
814 o ksh-like `ERR' trap
815
816 o `for' loops now allow empty word lists after the `in' reserved word
817
818 o new `hard' and `soft' arguments for the `ulimit' builtin
819
820 o Readline can be configured to place the user at the same point on the line
821   when retrieving commands from the history list
822
823 o Readline can be configured to skip `hidden' files (filenames with a leading
824   `.' on Unix) when performing completion
825
826 Bash-2.05 introduced the following new features:
827
828 o This version has once again reverted to using locales and strcoll(3) when
829   processing pattern matching bracket expressions, as POSIX requires. 
830 o Added a new `--init-file' invocation argument as a synonym for `--rcfile',
831   per the new GNU coding standards.
832 o The /dev/tcp and /dev/udp redirections now accept service names as well as
833   port numbers.
834 o `complete' and `compgen' now take a `-o value' option, which controls some
835    of the aspects of that compspec.  Valid values are:
836
837         default - perform bash default completion if programmable
838                   completion produces no matches
839         dirnames - perform directory name completion if programmable
840                    completion produces no matches
841         filenames - tell readline that the compspec produces filenames,
842                     so it can do things like append slashes to
843                     directory names and suppress trailing spaces
844 o A new loadable builtin, realpath, which canonicalizes and expands symlinks
845   in pathname arguments.
846 o When `set' is called without options, it prints function defintions in a
847   way that allows them to be reused as input.  This affects `declare' and 
848   `declare -p' as well.  This only happens when the shell is not in POSIX
849    mode, since POSIX.2 forbids this behavior.
850
851 Bash-2.04 introduced the following new features:
852
853 o Programmable word completion with the new `complete' and `compgen' builtins;
854   examples are provided in examples/complete/complete-examples
855 o `history' has a new `-d' option to delete a history entry
856 o `bind' has a new `-x' option to bind key sequences to shell commands
857 o The prompt expansion code has new `\j' and `\l' escape sequences
858 o The `no_empty_cmd_completion' shell option, if enabled, inhibits
859   command completion when TAB is typed on an empty line
860 o `help' has a new `-s' option to print a usage synopsis
861 o New arithmetic operators: var++, var--, ++var, --var, expr1,expr2 (comma)
862 o New ksh93-style arithmetic for command:
863         for ((expr1 ; expr2; expr3 )); do list; done
864 o `read' has new options: `-t', `-n', `-d', `-s'
865 o The redirection code handles several filenames specially:  /dev/fd/N,
866   /dev/stdin, /dev/stdout, /dev/stderr
867 o The redirection code now recognizes /dev/tcp/HOST/PORT and
868   /dev/udp/HOST/PORT and tries to open a TCP or UDP socket, respectively,
869   to the specified port on the specified host
870 o The ${!prefix*} expansion has been implemented
871 o A new FUNCNAME variable, which expands to the name of a currently-executing
872   function
873 o The GROUPS variable is no longer readonly
874 o A new shopt `xpg_echo' variable, to control the behavior of echo with
875   respect to backslash-escape sequences at runtime
876 o The NON_INTERACTIVE_LOGIN_SHELLS #define has returned
877
878 The version of Readline released with Bash-2.04, Readline-4.1, had several
879 new features as well:
880
881 o Parentheses matching is always compiled into readline, and controllable
882   with the new `blink-matching-paren' variable
883 o The history-search-forward and history-search-backward functions now leave
884   point at the end of the line when the search string is empty, like
885   reverse-search-history, and forward-search-history
886 o A new function for applications:  rl_on_new_line_with_prompt()
887 o New variables for applications:  rl_already_prompted, and rl_gnu_readline_p
888
889
890 Bash-2.03 had very few new features, in keeping with the convention
891 that odd-numbered releases provide mainly bug fixes.  A number of new
892 features were added to Readline, mostly at the request of the Cygnus
893 folks.
894
895 A new shopt option, `restricted_shell', so that startup files can test
896         whether or not the shell was started in restricted mode
897 Filename generation is now performed on the words between ( and ) in
898         compound array assignments (this is really a bug fix)
899 OLDPWD is now auto-exported, as POSIX.2 requires
900 ENV and BASH_ENV are read-only variables in a restricted shell
901 Bash may now be linked against an already-installed Readline library,
902         as long as the Readline library is version 4 or newer
903 All shells begun with the `--login' option will source the login shell
904         startup files, even if the shell is not interactive
905
906 There were lots of changes to the version of the Readline library released
907 along with Bash-2.03.  For a complete list of the changes, read the file
908 CHANGES in the Bash-2.03 distribution.
909
910 Bash-2.02 contained the following new features:
911
912 a new version of malloc (based on the old GNU malloc code in previous
913         bash versions) that is more page-oriented, more conservative
914         with memory usage, does not `orphan' large blocks when they
915         are freed, is usable on 64-bit machines, and has allocation
916         checking turned on unconditionally
917 POSIX.2-style globbing character classes ([:alpha:], [:alnum:], etc.)
918 POSIX.2-style globbing equivalence classes
919 POSIX.2-style globbing collating symbols
920 the ksh [[...]] extended conditional command
921 the ksh egrep-style extended pattern matching operators
922 a new `printf' builtin
923 the ksh-like $(<filename) command substitution, which is equivalent to
924         $(cat filename)
925 new tilde prefixes that expand to directories from the directory stack
926 new `**' arithmetic operator to do exponentiation
927 case-insensitive globbing (filename expansion)
928 menu completion a la tcsh
929 `magic-space' history expansion function like tcsh
930 the readline inputrc `language' has a new file inclusion directive ($include)
931
932 Bash-2.01 contained only a few new features:
933
934 new `GROUPS' builtin array variable containing the user's group list
935 new bindable readline commands: history-and-alias-expand-line and
936         alias-expand-line
937
938 Bash-2.0 contained extensive changes and new features from bash-1.14.7.
939 Here's a short list:
940
941 new `time' reserved word to time pipelines, shell builtins, and
942         shell functions
943 one-dimensional arrays with a new compound assignment statement,
944         appropriate expansion constructs and modifications to some
945         of the builtins (read, declare, etc.) to use them
946 new quoting syntaxes for ANSI-C string expansion and locale-specific
947         string translation
948 new expansions to do substring extraction, pattern replacement, and
949         indirect variable expansion
950 new builtins: `disown' and `shopt'
951 new variables: HISTIGNORE, SHELLOPTS, PIPESTATUS, DIRSTACK, GLOBIGNORE,
952                MACHTYPE, BASH_VERSINFO
953 special handling of many unused or redundant variables removed
954         (e.g., $notify, $glob_dot_filenames, $no_exit_on_failed_exec)
955 dynamic loading of new builtin commands; many loadable examples provided
956 new prompt expansions: \a, \e, \n, \H, \T, \@, \v, \V
957 history and aliases available in shell scripts
958 new readline variables: enable-keypad, mark-directories, input-meta,
959         visible-stats, disable-completion, comment-begin
960 new readline commands to manipulate the mark and operate on the region
961 new readline emacs mode commands and bindings for ksh-88 compatibility
962 updated and extended builtins
963 new DEBUG trap
964 expanded (and now documented) restricted shell mode
965
966 implementation stuff:   
967 autoconf-based configuration
968 nearly all of the bugs reported since version 1.14 have been fixed
969 most builtins converted to use builtin `getopt' for consistency
970 most builtins use -p option to display output in a reusable form
971         (for consistency)
972 grammar tighter and smaller (66 reduce-reduce conflicts gone)
973 lots of code now smaller and faster
974 test suite greatly expanded
975
976 B2) Are there any user-visible incompatibilities between bash-4.2 and
977     previous bash versions?
978
979 There are a few incompatibilities between version 4.2 and previous
980 versions.  They are detailed in the file COMPAT in the bash distribution.
981 That file is not meant to be all-encompassing; send mail to
982 bash-maintainers@gnu.org (or bug-bash@gnu.org if you would like
983 community discussion) if you find something that's not mentioned there.
984
985 Section C:  Differences from other Unix shells
986
987 C1) How does bash differ from sh, the Bourne shell?
988
989 This is a non-comprehensive list of features that differentiate bash
990 from the SVR4.2 shell.  The bash manual page explains these more
991 completely.
992
993 Things bash has that sh does not:
994         long invocation options
995         [+-]O invocation option
996         -l invocation option
997         `!' reserved word to invert pipeline return value
998         `time' reserved word to time pipelines and shell builtins
999         the `function' reserved word
1000         the `select' compound command and reserved word
1001         arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
1002         new $'...' and $"..." quoting
1003         the $(...) form of command substitution
1004         the $(<filename) form of command substitution, equivalent to
1005                 $(cat filename)
1006         the ${#param} parameter value length operator
1007         the ${!param} indirect parameter expansion operator
1008         the ${!param*} prefix expansion operator
1009         the ${param:offset[:length]} parameter substring operator
1010         the ${param/pat[/string]} parameter pattern substitution operator
1011         expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
1012         expansion of positional parameters beyond $9 with ${num}
1013         variables: BASH, BASHPID, BASH_VERSION, BASH_VERSINFO, UID, EUID, REPLY,
1014                    TIMEFORMAT, PPID, PWD, OLDPWD, SHLVL, RANDOM, SECONDS,
1015                    LINENO, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE, HOSTNAME,
1016                    ENV, PS3, PS4, DIRSTACK, PIPESTATUS, HISTSIZE, HISTFILE,
1017                    HISTFILESIZE, HISTCONTROL, HISTIGNORE, GLOBIGNORE, GROUPS,
1018                    PROMPT_COMMAND, FCEDIT, FIGNORE, IGNOREEOF, INPUTRC,
1019                    SHELLOPTS, OPTERR, HOSTFILE, TMOUT, FUNCNAME, histchars,
1020                    auto_resume, PROMPT_DIRTRIM, BASHOPTS, BASH_XTRACEFD
1021         DEBUG trap
1022         ERR trap
1023         variable arrays with new compound assignment syntax
1024         redirections: <>, &>, >|, <<<, [n]<&word-, [n]>&word-, >>&
1025         prompt string special char translation and variable expansion
1026         auto-export of variables in initial environment
1027         command search finds functions before builtins
1028         bash return builtin will exit a file sourced with `.'
1029         builtins: cd -/-L/-P, exec -l/-c/-a, echo -e/-E, hash -d/-l/-p/-t.
1030                   export -n/-f/-p/name=value, pwd -L/-P,
1031                   read -e/-p/-a/-t/-n/-d/-s/-u/-i/-N,
1032                   readonly -a/-f/name=value, trap -l, set +o,
1033                   set -b/-m/-o option/-h/-p/-B/-C/-H/-P,
1034                   unset -f/-v, ulimit -i/-m/-p/-q/-u/-x,
1035                   type -a/-p/-t/-f/-P, suspend -f, kill -n,
1036                   test -o optname/s1 == s2/s1 < s2/s1 > s2/-nt/-ot/-ef/-O/-G/-S
1037         bash reads ~/.bashrc for interactive shells, $ENV for non-interactive
1038         bash restricted shell mode is more extensive
1039         bash allows functions and variables with the same name
1040         brace expansion
1041         tilde expansion
1042         arithmetic expansion with $((...)) and `let' builtin
1043         the `[[...]]' extended conditional command
1044         process substitution
1045         aliases and alias/unalias builtins
1046         local variables in functions and `local' builtin
1047         readline and command-line editing with programmable completion
1048         command history and history/fc builtins
1049         csh-like history expansion
1050         other new bash builtins: bind, command, compgen, complete, builtin,
1051                                  declare/typeset, dirs, enable, fc, help,
1052                                  history, logout, popd, pushd, disown, shopt,
1053                                  printf, compopt, mapfile
1054         exported functions
1055         filename generation when using output redirection (command >a*)
1056         POSIX.2-style globbing character classes
1057         POSIX.2-style globbing equivalence classes
1058         POSIX.2-style globbing collating symbols
1059         egrep-like extended pattern matching operators
1060         case-insensitive pattern matching and globbing
1061         variable assignments preceding commands affect only that command,
1062                 even for builtins and functions
1063         posix mode and strict posix conformance
1064         redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr,
1065                 /dev/tcp/host/port, /dev/udp/host/port
1066         debugger support, including `caller' builtin and new variables
1067         RETURN trap
1068         the `+=' assignment operator
1069         autocd shell option and behavior
1070         command-not-found hook with command_not_found_handle shell function
1071         globstar shell option and `**' globbing behavior
1072         |& synonym for `2>&1 |'
1073         ;& and ;;& case action list terminators
1074         case-modifying word expansions and variable attributes
1075         associative arrays
1076         coprocesses using the `coproc' reserved word and variables
1077         shell assignment of a file descriptor used in a redirection to a variable
1078
1079 Things sh has that bash does not:
1080         uses variable SHACCT to do shell accounting
1081         includes `stop' builtin (bash can use alias stop='kill -s STOP')
1082         `newgrp' builtin
1083         turns on job control if called as `jsh'
1084         $TIMEOUT (like bash $TMOUT)
1085         `^' is a synonym for `|'
1086         new SVR4.2 sh builtins: mldmode, priv
1087
1088 Implementation differences:
1089         redirection to/from compound commands causes sh to create a subshell
1090         bash does not allow unbalanced quotes; sh silently inserts them at EOF
1091         bash does not mess with signal 11
1092         sh sets (euid, egid) to (uid, gid) if -p not supplied and uid < 100
1093         bash splits only the results of expansions on IFS, using POSIX.2
1094                 field splitting rules; sh splits all words on IFS
1095         sh does not allow MAILCHECK to be unset (?)
1096         sh does not allow traps on SIGALRM or SIGCHLD
1097         bash allows multiple option arguments when invoked (e.g. -x -v);
1098                 sh allows only a single option argument (`sh -x -v' attempts
1099                 to open a file named `-v', and, on SunOS 4.1.4, dumps core.
1100                 On Solaris 2.4 and earlier versions, sh goes into an infinite
1101                 loop.)
1102         sh exits a script if any builtin fails; bash exits only if one of
1103                 the POSIX.2 `special' builtins fails
1104
1105 C2)  How does bash differ from the Korn shell, version ksh88?
1106
1107 Things bash has or uses that ksh88 does not:
1108         long invocation options
1109         [-+]O invocation option
1110         -l invocation option
1111         `!' reserved word
1112         arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
1113         arithmetic in largest machine-supported size (intmax_t)
1114         posix mode and posix conformance
1115         command hashing
1116         tilde expansion for assignment statements that look like $PATH
1117         process substitution with named pipes if /dev/fd is not available
1118         the ${!param} indirect parameter expansion operator
1119         the ${!param*} prefix expansion operator
1120         the ${param:offset[:length]} parameter substring operator
1121         the ${param/pat[/string]} parameter pattern substitution operator
1122         variables: BASH, BASH_VERSION, BASH_VERSINFO, BASHPID, UID, EUID, SHLVL,
1123                    TIMEFORMAT, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE,
1124                    HISTFILESIZE, HISTIGNORE, HISTCONTROL, PROMPT_COMMAND,
1125                    IGNOREEOF, FIGNORE, INPUTRC, HOSTFILE, DIRSTACK,
1126                    PIPESTATUS, HOSTNAME, OPTERR, SHELLOPTS, GLOBIGNORE,
1127                    GROUPS, FUNCNAME, histchars, auto_resume, PROMPT_DIRTRIM
1128         prompt expansion with backslash escapes and command substitution
1129         redirection: &> (stdout and stderr), <<<, [n]<&word-, [n]>&word-, >>&
1130         more extensive and extensible editing and programmable completion
1131         builtins: bind, builtin, command, declare, dirs, echo -e/-E, enable,
1132                   exec -l/-c/-a, fc -s, export -n/-f/-p, hash, help, history,
1133                   jobs -x/-r/-s, kill -s/-n/-l, local, logout, popd, pushd,
1134                   read -e/-p/-a/-t/-n/-d/-s/-N, readonly -a/-n/-f/-p,
1135                   set -o braceexpand/-o histexpand/-o interactive-comments/
1136                   -o notify/-o physical/-o posix/-o hashall/-o onecmd/
1137                   -h/-B/-C/-b/-H/-P, set +o, suspend, trap -l, type,
1138                   typeset -a/-F/-p, ulimit -i/-q/-u/-x, umask -S, alias -p,
1139                   shopt, disown, printf, complete, compgen, compopt, mapfile
1140         `!' csh-style history expansion
1141         POSIX.2-style globbing character classes
1142         POSIX.2-style globbing equivalence classes
1143         POSIX.2-style globbing collating symbols
1144         egrep-like extended pattern matching operators
1145         case-insensitive pattern matching and globbing
1146         `**' arithmetic operator to do exponentiation
1147         redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr
1148         arrays of unlimited size
1149         TMOUT is default timeout for `read' and `select'
1150         debugger support, including the `caller' builtin
1151         RETURN trap
1152         Timestamps in history entries
1153         {x..y} brace expansion
1154         The `+=' assignment operator
1155         autocd shell option and behavior
1156         command-not-found hook with command_not_found_handle shell function
1157         globstar shell option and `**' globbing behavior
1158         |& synonym for `2>&1 |'
1159         ;& and ;;& case action list terminators
1160         case-modifying word expansions and variable attributes
1161         associative arrays
1162         coprocesses using the `coproc' reserved word and variables
1163         shell assignment of a file descriptor used in a redirection to a variable
1164
1165 Things ksh88 has or uses that bash does not:
1166         tracked aliases (alias -t)
1167         variables: ERRNO, FPATH, EDITOR, VISUAL
1168         co-processes (bash uses different syntax)
1169         weirdly-scoped functions
1170         typeset +f to list all function names without definitions
1171         text of command history kept in a file, not memory
1172         builtins: alias -x, cd old new, newgrp, print,
1173                   read -p/-s/var?prompt, set -A/-o gmacs/
1174                   -o bgnice/-o markdirs/-o trackall/-o viraw/-s,
1175                   typeset -H/-L/-R/-Z/-A/-ft/-fu/-fx/-t, whence
1176         using environment to pass attributes of exported variables
1177         arithmetic evaluation done on arguments to some builtins
1178         reads .profile from $PWD when invoked as login shell
1179
1180 Implementation differences:
1181         ksh runs last command of a pipeline in parent shell context
1182         bash has brace expansion by default (ksh88 compile-time option)
1183         bash has fixed startup file for all interactive shells; ksh reads $ENV
1184         bash has exported functions
1185         bash command search finds functions before builtins
1186         bash waits for all commands in pipeline to exit before returning status
1187         emacs-mode editing has some slightly different key bindings
1188
1189 C3)  Which new features in ksh-93 are not in bash, and which are?
1190
1191 This list is current through ksh93t+ (05/05/2009)
1192
1193 New things in ksh-93 not in bash-4.2:
1194         floating point arithmetic and variables
1195         math library functions
1196         ${!name[sub]} name of subscript for associative array
1197         `.' is allowed in variable names to create a hierarchical namespace
1198         more extensive compound assignment syntax
1199         discipline functions
1200         KEYBD trap
1201         variables: .sh.edchar, .sh.edmode, .sh.edcol, .sh.edtext, .sh.version,
1202                    .sh.name, .sh.subscript, .sh.value, .sh.match, HISTEDIT
1203         backreferences in pattern matching (\N)
1204         `&' operator in pattern lists for matching (match all instead of any)
1205         exit statuses between 0 and 255
1206         FPATH and PATH mixing
1207         lexical scoping for local variables in `ksh' functions
1208         no scoping for local variables in `POSIX' functions
1209         $''  \C[.collating-element.] escape sequence
1210         -C/-I invocation options
1211         print -f (bash uses printf)
1212         `fc' has been renamed to `hist'
1213         `.' can execute shell functions
1214         getopts -a
1215         printf %B, %H, %P, %R, %Z modifiers, output base for %d, `=' flag
1216         read -n/-N differ/-v
1217         set -o showme/-o multiline (bash default)
1218         `sleep' and `getconf' builtins (bash has loadable versions)
1219         typeset -n and `nameref' variables
1220         [[ -R name ]] (checks whether or not name is a nameref)
1221         typeset -C/-S/-T/-X/-h/-s
1222         experimental `type' definitions (a la typedef) using typeset
1223         array expansions ${array[sub1..sub2]} and ${!array[sub1..sub2]}
1224         associative array assignments using `;' as element separator
1225         command substitution $(n<#) expands to current byte offset for fd N
1226         new '${ ' form of command substitution, executed in current shell
1227         new >;/<>;/<#pat/<##pat/<#/># redirections
1228         brace expansion printf-like formats 
1229
1230 New things in ksh-93 present in bash-4.2:
1231         associative arrays
1232         [n]<&word- and [n]>&word- redirections (combination dup and close)
1233         for (( expr1; expr2; expr3 )) ; do list; done - arithmetic for command
1234         ?:, ++, --, `expr1 , expr2' arithmetic operators
1235         expansions: ${!param}, ${param:offset[:len]}, ${param/pat[/str]},
1236                     ${!param*}
1237         compound array assignment
1238         negative subscripts for indexed array variables
1239         the `!' reserved word
1240         loadable builtins -- but ksh uses `builtin' while bash uses `enable'
1241         new $'...' and $"..." quoting
1242         FIGNORE (but bash uses GLOBIGNORE), HISTCMD
1243         brace expansion and set -B
1244         changes to kill builtin
1245         `command', `builtin', `disown' builtins
1246         echo -e
1247         exec -c/-a
1248         printf %T modifier
1249         read -A (bash uses read -a)
1250         read -t/-d
1251         trap -p
1252         `.' restores the positional parameters when it completes
1253         set -o notify/-C
1254         set -o pipefail
1255         set -G (-o globstar) and **
1256         POSIX.2 `test'
1257         umask -S
1258         unalias -a
1259         command and arithmetic substitution performed on PS1, PS4, and ENV
1260         command name completion, TAB displaying possible completions
1261         ENV processed only for interactive shells
1262         The `+=' assignment operator
1263         the `;&' case statement "fallthrough" pattern list terminator
1264         csh-style history expansion and set -H
1265         negative offsets in ${param:offset:length}
1266         redirection operators preceded with {varname} to store fd number in varname
1267         DEBUG can force skipping following command
1268         [[ -v var ]] operator (checks whether or not var is set)
1269
1270 Section D:  Why does bash do some things differently than other Unix shells?
1271
1272 D1) Why does bash run a different version of `command' than
1273     `which command' says it will?
1274
1275 On many systems, `which' is actually a csh script that assumes
1276 you're running csh.  In tcsh, `which' and its cousin `where'
1277 are builtins.  On other Unix systems, `which' is a perl script
1278 that uses the PATH environment variable.  Many Linux distributions
1279 use GNU `which', which is a C program that can understand shell
1280 aliases.
1281
1282 The csh script version reads the csh startup files from your
1283 home directory and uses those to determine which `command' will
1284 be invoked.  Since bash doesn't use any of those startup files,
1285 there's a good chance that your bash environment differs from
1286 your csh environment.  The bash `type' builtin does everything
1287 `which' does, and will report correct results for the running
1288 shell.  If you're really wedded to the name `which', try adding
1289 the following function definition to your .bashrc:
1290
1291         which()
1292         {
1293                 builtin type "$@"
1294         }
1295
1296 If you're moving from tcsh and would like to bring `where' along
1297 as well, use this function:
1298
1299         where()
1300         {
1301                 builtin type -a "$@"
1302         }
1303
1304 D2) Why doesn't bash treat brace expansions exactly like csh?
1305
1306 The only difference between bash and csh brace expansion is that
1307 bash requires a brace expression to contain at least one unquoted
1308 comma if it is to be expanded.  Any brace-surrounded word not
1309 containing an unquoted comma is left unchanged by the brace
1310 expansion code.  This affords the greatest degree of sh
1311 compatibility. 
1312
1313 Bash, ksh, zsh, and pd-ksh all implement brace expansion this way. 
1314
1315 D3) Why doesn't bash have csh variable modifiers?
1316
1317 Posix has specified a more powerful, albeit somewhat more cryptic,
1318 mechanism cribbed from ksh, and bash implements it.
1319
1320 ${parameter%word}
1321         Remove smallest suffix pattern.  The WORD is expanded to produce
1322         a pattern.  It then expands to the value of PARAMETER, with the
1323         smallest portion of the suffix matched by the pattern deleted.
1324
1325         x=file.c
1326         echo ${x%.c}.o
1327         -->file.o
1328
1329 ${parameter%%word}
1330
1331         Remove largest suffix pattern.  The WORD is expanded to produce
1332         a pattern.  It then expands to the value of PARAMETER, with the
1333         largest portion of the suffix matched by the pattern deleted.
1334
1335         x=posix/src/std
1336         echo ${x%%/*}
1337         -->posix
1338
1339 ${parameter#word}
1340         Remove smallest prefix pattern.  The WORD is expanded to produce
1341         a pattern.  It then expands to the value of PARAMETER, with the
1342         smallest portion of the prefix matched by the pattern deleted.
1343
1344         x=$HOME/src/cmd
1345         echo ${x#$HOME}
1346         -->/src/cmd
1347
1348 ${parameter##word}
1349         Remove largest prefix pattern.  The WORD is expanded to produce
1350         a pattern.  It then expands to the value of PARAMETER, with the
1351         largest portion of the prefix matched by the pattern deleted.
1352
1353         x=/one/two/three
1354         echo ${x##*/}
1355         -->three
1356
1357
1358 Given
1359         a=/a/b/c/d
1360         b=b.xxx
1361
1362         csh                     bash            result
1363         ---                     ----            ------
1364         $a:h                    ${a%/*}            /a/b/c
1365         $a:t                    ${a##*/}           d
1366         $b:r                    ${b%.*}            b
1367         $b:e                    ${b##*.}           xxx
1368
1369
1370 D4) How can I make my csh aliases work when I convert to bash?
1371
1372 Bash uses a different syntax to support aliases than csh does. 
1373 The details can be found in the documentation.  We have provided
1374 a shell script which does most of the work of conversion for you;
1375 this script can be found in ./examples/misc/aliasconv.sh.  Here is
1376 how you use it:
1377   
1378 Start csh in the normal way for you.  (e.g., `csh')
1379   
1380 Pipe the output of `alias' through `aliasconv.sh', saving the
1381 results into `bash_aliases':
1382   
1383         alias | bash aliasconv.sh >bash_aliases
1384   
1385 Edit `bash_aliases', carefully reading through any created
1386 functions.  You will need to change the names of some csh specific
1387 variables to the bash equivalents.  The script converts $cwd to
1388 $PWD, $term to $TERM, $home to $HOME, $user to $USER, and $prompt
1389 to $PS1.  You may also have to add quotes to avoid unwanted
1390 expansion.
1391
1392 For example, the csh alias:
1393   
1394         alias cd 'cd \!*; echo $cwd'
1395   
1396 is converted to the bash function:
1397
1398         cd () { command cd "$@"; echo $PWD ; }
1399
1400 The only thing that needs to be done is to quote $PWD:
1401   
1402         cd () { command cd "$@"; echo "$PWD" ; }
1403   
1404 Merge the edited file into your ~/.bashrc.
1405
1406 There is an additional, more ambitious, script in
1407 examples/misc/cshtobash that attempts to convert your entire csh
1408 environment to its bash equivalent.  This script can be run as
1409 simply `cshtobash' to convert your normal interactive
1410 environment, or as `cshtobash ~/.login' to convert your login
1411 environment. 
1412
1413 D5) How can I pipe standard output and standard error from one command to
1414     another, like csh does with `|&'?
1415
1416 Use
1417         command 2>&1 | command2
1418
1419 The key is to remember that piping is performed before redirection, so
1420 file descriptor 1 points to the pipe when it is duplicated onto file
1421 descriptor 2.
1422
1423 D6) Now that I've converted from ksh to bash, are there equivalents to
1424     ksh features like autoloaded functions and the `whence' command?
1425
1426 There are features in ksh-88 and ksh-93 that do not have direct bash
1427 equivalents.  Most, however, can be emulated with very little trouble.
1428
1429 ksh-88 feature          Bash equivalent
1430 --------------          ---------------
1431 compiled-in aliases     set up aliases in .bashrc; some ksh aliases are
1432                         bash builtins (hash, history, type)
1433 coprocesses             named pipe pairs (one for read, one for write)
1434 typeset +f              declare -F
1435 cd, print, whence       function substitutes in examples/functions/kshenv
1436 autoloaded functions    examples/functions/autoload is the same as typeset -fu
1437 read var?prompt         read -p prompt var
1438
1439 ksh-93 feature          Bash equivalent
1440 --------------          ---------------
1441 sleep, getconf          Bash has loadable versions in examples/loadables
1442 ${.sh.version}          $BASH_VERSION
1443 print -f                printf
1444 hist                    alias hist=fc
1445 $HISTEDIT               $FCEDIT
1446
1447 Section E:  How can I get bash to do certain things, and why does bash do
1448             things the way it does?
1449
1450 E1) Why is the bash builtin `test' slightly different from /bin/test?
1451
1452 The specific example used here is [ ! x -o x ], which is false.
1453
1454 Bash's builtin `test' implements the Posix.2 spec, which can be
1455 summarized as follows (the wording is due to David Korn):
1456    
1457 Here is the set of rules for processing test arguments.
1458   
1459     0 Args: False
1460     1 Arg:  True iff argument is not null.
1461     2 Args: If first arg is !, True iff second argument is null.
1462             If first argument is unary, then true if unary test is true
1463             Otherwise error.
1464     3 Args: If second argument is a binary operator, do binary test of $1 $3
1465             If first argument is !, negate two argument test of $2 $3
1466             If first argument is `(' and third argument is `)', do the
1467             one-argument test of the second argument.
1468             Otherwise error.
1469     4 Args: If first argument is !, negate three argument test of $2 $3 $4.
1470             Otherwise unspecified
1471     5 or more Args: unspecified.  (Historical shells would use their
1472     current algorithm).
1473    
1474 The operators -a and -o are considered binary operators for the purpose
1475 of the 3 Arg case.
1476    
1477 As you can see, the test becomes (not (x or x)), which is false.
1478
1479 E2) Why does bash sometimes say `Broken pipe'?
1480
1481 If a sequence of commands appears in a pipeline, and one of the
1482 reading commands finishes before the writer has finished, the
1483 writer receives a SIGPIPE signal.  Many other shells special-case
1484 SIGPIPE as an exit status in the pipeline and do not report it. 
1485 For example, in:
1486   
1487       ps -aux | head
1488   
1489 `head' can finish before `ps' writes all of its output, and ps
1490 will try to write on a pipe without a reader.  In that case, bash
1491 will print `Broken pipe' to stderr when ps is killed by a
1492 SIGPIPE. 
1493
1494 As of bash-3.1, bash does not report SIGPIPE errors by default.  You
1495 can build a version of bash that will report such errors.
1496
1497 E3) When I have terminal escape sequences in my prompt, why does bash
1498     wrap lines at the wrong column?
1499
1500 Readline, the line editing library that bash uses, does not know
1501 that the terminal escape sequences do not take up space on the
1502 screen.  The redisplay code assumes, unless told otherwise, that
1503 each character in the prompt is a `printable' character that
1504 takes up one character position on the screen. 
1505
1506 You can use the bash prompt expansion facility (see the PROMPTING
1507 section in the manual page) to tell readline that sequences of
1508 characters in the prompt strings take up no screen space. 
1509
1510 Use the \[ escape to begin a sequence of non-printing characters,
1511 and the \] escape to signal the end of such a sequence. 
1512
1513 E4) If I pipe the output of a command into `read variable', why doesn't
1514     the output show up in $variable when the read command finishes?
1515
1516 This has to do with the parent-child relationship between Unix
1517 processes.  It affects all commands run in pipelines, not just
1518 simple calls to `read'.  For example, piping a command's output
1519 into a `while' loop that repeatedly calls `read' will result in
1520 the same behavior.
1521
1522 Each element of a pipeline, even a builtin or shell function,
1523 runs in a separate process, a child of the shell running the
1524 pipeline.  A subprocess cannot affect its parent's environment. 
1525 When the `read' command sets the variable to the input, that
1526 variable is set only in the subshell, not the parent shell.  When
1527 the subshell exits, the value of the variable is lost. 
1528
1529 Many pipelines that end with `read variable' can be converted
1530 into command substitutions, which will capture the output of
1531 a specified command.  The output can then be assigned to a
1532 variable:
1533
1534         grep ^gnu /usr/lib/news/active | wc -l | read ngroup
1535
1536 can be converted into
1537
1538         ngroup=$(grep ^gnu /usr/lib/news/active | wc -l)
1539
1540 This does not, unfortunately, work to split the text among
1541 multiple variables, as read does when given multiple variable
1542 arguments.  If you need to do this, you can either use the
1543 command substitution above to read the output into a variable
1544 and chop up the variable using the bash pattern removal
1545 expansion operators or use some variant of the following
1546 approach.
1547
1548 Say /usr/local/bin/ipaddr is the following shell script:
1549
1550 #! /bin/sh
1551 host `hostname` | awk '/address/ {print $NF}'
1552
1553 Instead of using
1554
1555         /usr/local/bin/ipaddr | read A B C D
1556
1557 to break the local machine's IP address into separate octets, use
1558
1559         OIFS="$IFS"
1560         IFS=.
1561         set -- $(/usr/local/bin/ipaddr)
1562         IFS="$OIFS"
1563         A="$1" B="$2" C="$3" D="$4"
1564
1565 Beware, however, that this will change the shell's positional
1566 parameters.  If you need them, you should save them before doing
1567 this.
1568
1569 This is the general approach -- in most cases you will not need to
1570 set $IFS to a different value.
1571
1572 Some other user-supplied alternatives include:
1573
1574 read A B C D << HERE
1575     $(IFS=.; echo $(/usr/local/bin/ipaddr))
1576 HERE
1577
1578 and, where process substitution is available,
1579
1580 read A B C D < <(IFS=.; echo $(/usr/local/bin/ipaddr))
1581
1582 E5) I have a bunch of shell scripts that use backslash-escaped characters
1583     in arguments to `echo'.  Bash doesn't interpret these characters.  Why
1584     not, and how can I make it understand them?
1585
1586 This is the behavior of echo on most Unix System V machines.
1587
1588 The bash builtin `echo' is modeled after the 9th Edition
1589 Research Unix version of `echo'.  It does not interpret
1590 backslash-escaped characters in its argument strings by default;
1591 it requires the use of the -e option to enable the
1592 interpretation.  The System V echo provides no way to disable the
1593 special characters; the bash echo has a -E option to disable
1594 them. 
1595
1596 There is a configuration option that will make bash behave like
1597 the System V echo and interpret things like `\t' by default.  Run
1598 configure with the --enable-xpg-echo-default option to turn this
1599 on.  Be aware that this will cause some of the tests run when you
1600 type `make tests' to fail.
1601
1602 There is a shell option, `xpg_echo', settable with `shopt', that will
1603 change the behavior of echo at runtime.  Enabling this option turns
1604 on expansion of backslash-escape sequences.
1605
1606 E6) Why doesn't a while or for loop get suspended when I type ^Z?
1607
1608 This is a consequence of how job control works on Unix.  The only
1609 thing that can be suspended is the process group.  This is a single
1610 command or pipeline of commands that the shell forks and executes.
1611
1612 When you run a while or for loop, the only thing that the shell forks
1613 and executes are any commands in the while loop test and commands in
1614 the loop bodies.  These, therefore, are the only things that can be
1615 suspended when you type ^Z.
1616
1617 If you want to be able to stop the entire loop, you need to put it
1618 within parentheses, which will force the loop into a subshell that
1619 may be stopped (and subsequently restarted) as a single unit.
1620
1621 E7) What about empty for loops in Makefiles?
1622
1623 It's fairly common to see constructs like this in automatically-generated
1624 Makefiles:
1625
1626 SUBDIRS = @SUBDIRS@
1627
1628         ...
1629
1630 subdirs-clean:
1631         for d in ${SUBDIRS}; do \
1632                 ( cd $$d && ${MAKE} ${MFLAGS} clean ) \
1633         done
1634
1635 When SUBDIRS is empty, this results in a command like this being passed to
1636 bash:
1637
1638         for d in ; do
1639                 ( cd $d && ${MAKE} ${MFLAGS} clean )
1640         done
1641
1642 In versions of bash before bash-2.05a, this was a syntax error.  If the
1643 reserved word `in' was present, a word must follow it before the semicolon
1644 or newline.  The language in the manual page referring to the list of words
1645 being empty referred to the list after it is expanded.  These versions of
1646 bash required that there be at least one word following the `in' when the
1647 construct was parsed.
1648
1649 The idiomatic Makefile solution is something like:
1650
1651 SUBDIRS = @SUBDIRS@
1652
1653 subdirs-clean:
1654         subdirs=$SUBDIRS ; for d in $$subdirs; do \
1655                 ( cd $$d && ${MAKE} ${MFLAGS} clean ) \
1656         done
1657
1658 The latest updated POSIX standard has changed this:  the word list
1659 is no longer required.  Bash versions 2.05a and later accept the
1660 new syntax.
1661
1662 E8) Why does the arithmetic evaluation code complain about `08'?
1663
1664 The bash arithmetic evaluation code (used for `let', $(()), (()), and in
1665 other places), interprets a leading `0' in numeric constants as denoting
1666 an octal number, and a leading `0x' as denoting hexadecimal.  This is
1667 in accordance with the POSIX.2 spec, section 2.9.2.1, which states that
1668 arithmetic constants should be handled as signed long integers as defined
1669 by the ANSI/ISO C standard.
1670
1671 The POSIX.2 interpretation committee has confirmed this:
1672
1673 http://www.pasc.org/interps/unofficial/db/p1003.2/pasc-1003.2-173.html
1674
1675 E9) Why does the pattern matching expression [A-Z]* match files beginning
1676     with every letter except `z'?
1677
1678 Bash-2.03, Bash-2.05 and later versions honor the current locale setting
1679 when processing ranges within pattern matching bracket expressions ([A-Z]). 
1680 This is what POSIX.2 and SUSv3/XPG6 specify. 
1681
1682 The behavior of the matcher in bash-2.05 and later versions depends on the
1683 current LC_COLLATE setting.  Setting this variable to `C' or `POSIX' will
1684 result in the traditional behavior ([A-Z] matches all uppercase ASCII
1685 characters).  Many other locales, including the en_US locale (the default
1686 on many US versions of Linux) collate the upper and lower case letters like
1687 this:
1688
1689         AaBb...Zz
1690
1691 which means that [A-Z] matches every letter except `z'.  Others collate like
1692
1693         aAbBcC...zZ
1694
1695 which means that [A-Z] matches every letter except `a'.
1696
1697 The portable way to specify upper case letters is [:upper:] instead of
1698 A-Z; lower case may be specified as [:lower:] instead of a-z.
1699
1700 Look at the manual pages for setlocale(3), strcoll(3), and, if it is
1701 present, locale(1).  If you have locale(1), you can use it to find
1702 your current locale information even if you do not have any of the
1703 LC_ variables set.
1704
1705 My advice is to put
1706
1707         export LC_COLLATE=C
1708
1709 into /etc/profile and inspect any shell scripts run from cron for
1710 constructs like [A-Z].  This will prevent things like
1711
1712         rm [A-Z]*
1713
1714 from removing every file in the current directory except those beginning
1715 with `z' and still allow individual users to change the collation order.
1716 Users may put the above command into their own profiles as well, of course.
1717
1718 E10) Why does `cd //' leave $PWD as `//'?
1719
1720 POSIX.2, in its description of `cd', says that *three* or more leading
1721 slashes may be replaced with a single slash when canonicalizing the
1722 current working directory.
1723
1724 This is, I presume, for historical compatibility.  Certain versions of
1725 Unix, and early network file systems, used paths of the form
1726 //hostname/path to access `path' on server `hostname'.
1727
1728 E11) If I resize my xterm while another program is running, why doesn't bash
1729      notice the change?
1730
1731 This is another issue that deals with job control.
1732
1733 The kernel maintains a notion of a current terminal process group.  Members
1734 of this process group (processes whose process group ID is equal to the
1735 current terminal process group ID) receive terminal-generated signals like
1736 SIGWINCH.  (For more details, see the JOB CONTROL section of the bash
1737 man page.)
1738
1739 If a terminal is resized, the kernel sends SIGWINCH to each member of
1740 the terminal's current process group (the `foreground' process group).
1741
1742 When bash is running with job control enabled, each pipeline (which may be
1743 a single command) is run in its own process group, different from bash's
1744 process group.  This foreground process group receives the SIGWINCH; bash
1745 does not.  Bash has no way of knowing that the terminal has been resized.
1746
1747 There is a `checkwinsize' option, settable with the `shopt' builtin, that
1748 will cause bash to check the window size and adjust its idea of the
1749 terminal's dimensions each time a process stops or exits and returns control
1750 of the terminal to bash.  Enable it with `shopt -s checkwinsize'.
1751
1752 E12) Why don't negative offsets in substring expansion work like I expect?
1753
1754 When substring expansion of the form ${param:offset[:length} is used,
1755 an `offset' that evaluates to a number less than zero counts back from
1756 the end of the expanded value of $param.
1757
1758 When a negative `offset' begins with a minus sign, however, unexpected things
1759 can happen.  Consider
1760
1761         a=12345678
1762         echo ${a:-4}
1763
1764 intending to print the last four characters of $a.  The problem is that
1765 ${param:-word} already has a well-defined meaning: expand to word if the
1766 expanded value of param is unset or null, and $param otherwise.
1767
1768 To use negative offsets that begin with a minus sign, separate the
1769 minus sign and the colon with a space.
1770
1771 E13) Why does filename completion misbehave if a colon appears in the filename?
1772
1773 Filename completion (and word completion in general) may appear to behave
1774 improperly if there is a colon in the word to be completed.
1775
1776 The colon is special to readline's word completion code:  it is one of the
1777 characters that breaks words for the completer.  Readline uses these characters
1778 in sort of the same way that bash uses $IFS: they break or separate the words
1779 the completion code hands to the application-specific or default word
1780 completion functions.  The original intent was to make it easy to edit
1781 colon-separated lists (such as $PATH in bash) in various applications using
1782 readline for input.
1783
1784 This is complicated by the fact that some versions of the popular
1785 `bash-completion' programmable completion package have problems with the
1786 default completion behavior in the presence of colons.  
1787
1788 The current set of completion word break characters is available in bash as
1789 the value of the COMP_WORDBREAKS variable.  Removing `:' from that value is
1790 enough to make the colon not special to completion:
1791
1792 COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
1793
1794 You can also quote the colon with a backslash to achieve the same result
1795 temporarily.
1796
1797 E14) Why does quoting the pattern argument to the regular expression matching
1798      conditional operator (=~) cause regexp matching to stop working?
1799
1800 In versions of bash prior to bash-3.2, the effect of quoting the regular
1801 expression argument to the [[ command's =~ operator was not specified.
1802 The practical effect was that double-quoting the pattern argument required
1803 backslashes to quote special pattern characters, which interfered with the
1804 backslash processing performed by double-quoted word expansion and was
1805 inconsistent with how the == shell pattern matching operator treated
1806 quoted characters.
1807
1808 In bash-3.2, the shell was changed to internally quote characters in single-
1809 and double-quoted string arguments to the =~ operator, which suppresses the
1810 special meaning of the characters special to regular expression processing
1811 (`.', `[', `\', `(', `), `*', `+', `?', `{', `|', `^', and `$') and forces
1812 them to be matched literally.  This is consistent with how the `==' pattern
1813 matching operator treats quoted portions of its pattern argument.
1814
1815 Since the treatment of quoted string arguments was changed, several issues
1816 have arisen, chief among them the problem of white space in pattern arguments
1817 and the differing treatment of quoted strings between bash-3.1 and bash-3.2.
1818 Both problems may be solved by using a shell variable to hold the pattern.
1819 Since word splitting is not performed when expanding shell variables in all
1820 operands of the [[ command, this allows users to quote patterns as they wish
1821 when assigning the variable, then expand the values to a single string that
1822 may contain whitespace.  The first problem may be solved by using backslashes
1823 or any other quoting mechanism to escape the white space in the patterns.
1824
1825 Bash-4.0 introduces the concept of a `compatibility level', controlled by
1826 several options to the `shopt' builtin.  If the `compat31' option is enabled,
1827 bash reverts to the bash-3.1 behavior with respect to quoting the rhs of
1828 the =~ operator.
1829
1830 E15) Tell me more about the shell compatibility level.
1831
1832 Bash-4.0 introduced the concept of a `shell compatibility level', specified
1833 as a set of options to the shopt builtin (compat31, compat32, compat40 at
1834 this writing).  There is only one current compatibility level -- each
1835 option is mutually exclusive.  This list does not mention behavior that is
1836 standard for a particular version (e.g., setting compat32 means that quoting
1837 the rhs of the regexp matching operator quotes special regexp characters in
1838 the word, which is default behavior in bash-3.2 and above).
1839
1840 compat31 set
1841         - the < and > operators to the [[ command do not consider the current
1842           locale when comparing strings
1843         - quoting the rhs of the regexp matching operator (=~) has no
1844           special effect
1845
1846 compat32 set
1847         - the < and > operators to the [[ command do not consider the current
1848           locale when comparing strings
1849
1850 compat40 set
1851         - the < and > operators to the [[ command do not consider the current
1852           locale when comparing strings
1853         - interrupting a command list such as "a ; b ; c" causes the execution
1854           of the entire list to be aborted (in versions before bash-4.0,
1855           interrupting one command in a list caused the next to be executed)
1856
1857 Section F:  Things to watch out for on certain Unix versions
1858
1859 F1) Why can't I use command line editing in my `cmdtool'?
1860
1861 The problem is `cmdtool' and bash fighting over the input.  When
1862 scrolling is enabled in a cmdtool window, cmdtool puts the tty in
1863 `raw mode' to permit command-line editing using the mouse for
1864 applications that cannot do it themselves.  As a result, bash and
1865 cmdtool each try to read keyboard input immediately, with neither
1866 getting enough of it to be useful.
1867
1868 This mode also causes cmdtool to not implement many of the
1869 terminal functions and control sequences appearing in the
1870 `sun-cmd' termcap entry.  For a more complete explanation, see
1871 that file examples/suncmd.termcap in the bash distribution. 
1872
1873 `xterm' is a better choice, and gets along with bash much more
1874 smoothly.
1875
1876 If you must use cmdtool, you can use the termcap description in
1877 examples/suncmd.termcap.  Set the TERMCAP variable to the terminal
1878 description contained in that file, i.e.
1879
1880 TERMCAP='Mu|sun-cmd:am:bs:km:pt:li#34:co#80:cl=^L:ce=\E[K:cd=\E[J:rs=\E[s:'
1881
1882 Then export TERMCAP and start a new cmdtool window from that shell.
1883 The bash command-line editing should behave better in the new
1884 cmdtool.  If this works, you can put the assignment to TERMCAP
1885 in your bashrc file.
1886
1887 F2) I built bash on Solaris 2.  Why do globbing expansions and filename
1888     completion chop off the first few characters of each filename?
1889
1890 This is the consequence of building bash on SunOS 5 and linking
1891 with the libraries in /usr/ucblib, but using the definitions
1892 and structures from files in /usr/include. 
1893
1894 The actual conflict is between the dirent structure in
1895 /usr/include/dirent.h and the struct returned by the version of
1896 `readdir' in libucb.a (a 4.3-BSD style `struct direct'). 
1897
1898 Make sure you've got /usr/ccs/bin ahead of /usr/ucb in your $PATH
1899 when configuring and building bash.  This will ensure that you
1900 use /usr/ccs/bin/cc or acc instead of /usr/ucb/cc and that you
1901 link with libc before libucb. 
1902
1903 If you have installed the Sun C compiler, you may also need to
1904 put /usr/ccs/bin and /opt/SUNWspro/bin into your $PATH before
1905 /usr/ucb.
1906
1907 F3) Why does bash dump core after I interrupt username completion or
1908     `~user' tilde expansion on a machine running NIS?
1909
1910 This is a famous and long-standing bug in the SunOS YP (sorry, NIS)
1911 client library, which is part of libc.
1912
1913 The YP library code keeps static state -- a pointer into the data
1914 returned from the server.  When YP initializes itself (setpwent),
1915 it looks at this pointer and calls free on it if it's non-null. 
1916 So far, so good. 
1917
1918 If one of the YP functions is interrupted during getpwent (the
1919 exact function is interpretwithsave()), and returns NULL, the
1920 pointer is freed without being reset to NULL, and the function
1921 returns.  The next time getpwent is called, it sees that this
1922 pointer is non-null, calls free, and the bash free() blows up
1923 because it's being asked to free freed memory. 
1924
1925 The traditional Unix mallocs allow memory to be freed multiple
1926 times; that's probably why this has never been fixed.  You can
1927 run configure with the `--without-gnu-malloc' option to use
1928 the C library malloc and avoid the problem.
1929
1930 F4) I'm running SVR4.2.  Why is the line erased every time I type `@'?
1931
1932 The `@' character is the default `line kill' character in most
1933 versions of System V, including SVR4.2.  You can change this
1934 character to whatever you want using `stty'.  For example, to
1935 change the line kill character to control-u, type
1936
1937         stty kill ^U
1938
1939 where the `^' and `U' can be two separate characters.
1940
1941 F5) Why does bash report syntax errors when my C News scripts use a
1942     redirection before a subshell command?
1943
1944 The actual command in question is something like
1945
1946         < file ( command )
1947
1948 According to the grammar given in the POSIX.2 standard, this construct
1949 is, in fact, a syntax error.  Redirections may only precede `simple
1950 commands'.  A subshell construct such as the above is one of the shell's
1951 `compound commands'.  A redirection may only follow a compound command.
1952
1953 This affects the mechanical transformation of commands that use `cat'
1954 to pipe a file into a command (a favorite Useless-Use-Of-Cat topic on
1955 comp.unix.shell).  While most commands of the form
1956
1957         cat file | command
1958
1959 can be converted to `< file command', shell control structures such as
1960 loops and subshells require `command < file'.
1961
1962 The file CWRU/sh-redir-hack in the bash distribution is an
1963 (unofficial) patch to parse.y that will modify the grammar to
1964 support this construct.  It will not apply with `patch'; you must
1965 modify parse.y by hand.  Note that if you apply this, you must
1966 recompile with -DREDIRECTION_HACK.  This introduces a large
1967 number of reduce/reduce conflicts into the shell grammar. 
1968
1969 F6) Why can't I use vi-mode editing on Red Hat Linux 6.1?
1970
1971 The short answer is that Red Hat screwed up.
1972
1973 The long answer is that they shipped an /etc/inputrc that only works
1974 for emacs mode editing, and then screwed all the vi users by setting
1975 INPUTRC to /etc/inputrc in /etc/profile.
1976
1977 The short fix is to do one of the following: remove or rename
1978 /etc/inputrc, set INPUTRC=~/.inputrc in ~/.bashrc (or .bash_profile,
1979 but make sure you export it if you do), remove the assignment to
1980 INPUTRC from /etc/profile, add
1981
1982         set keymap emacs
1983
1984 to the beginning of /etc/inputrc, or bracket the key bindings in
1985 /etc/inputrc with these lines
1986
1987         $if mode=emacs
1988                 [...]
1989         $endif
1990
1991 F7) Why do bash-2.05a and bash-2.05b fail to compile `printf.def' on
1992     HP/UX 11.x?
1993
1994 HP/UX's support for long double is imperfect at best.
1995
1996 GCC will support it without problems, but the HP C library functions
1997 like strtold(3) and printf(3) don't actually work with long doubles.
1998 HP implemented a `long_double' type as a 4-element array of 32-bit
1999 ints, and that is what the library functions use.  The ANSI C
2000 `long double' type is a 128-bit floating point scalar.
2001
2002 The easiest fix, until HP fixes things up, is to edit the generated
2003 config.h and #undef the HAVE_LONG_DOUBLE line.  After doing that,
2004 the compilation should complete successfully.
2005
2006 Section G:  How can I get bash to do certain common things?
2007
2008 G1) How can I get bash to read and display eight-bit characters?
2009
2010 This is a process requiring several steps.
2011
2012 First, you must ensure that the `physical' data path is a full eight
2013 bits.  For xterms, for example, the `vt100' resources `eightBitInput'
2014 and `eightBitOutput' should be set to `true'.
2015
2016 Once you have set up an eight-bit path, you must tell the kernel and
2017 tty driver to leave the eighth bit of characters alone when processing
2018 keyboard input.  Use `stty' to do this:
2019
2020         stty cs8 -istrip -parenb
2021
2022 For old BSD-style systems, you can use
2023
2024         stty pass8
2025
2026 You may also need
2027
2028         stty even odd
2029
2030 Finally, you need to tell readline that you will be inputting and
2031 displaying eight-bit characters.  You use readline variables to do
2032 this.  These variables can be set in your .inputrc or using the bash
2033 `bind' builtin.  Here's an example using `bind':
2034
2035         bash$ bind 'set convert-meta off'
2036         bash$ bind 'set meta-flag on'
2037         bash$ bind 'set output-meta on'
2038
2039 The `set' commands between the single quotes may also be placed
2040 in ~/.inputrc.
2041
2042 The script examples/scripts.noah/meta.bash encapsulates the bind
2043 commands in a shell function.
2044
2045 G2) How do I write a function `x' to replace builtin command `x', but
2046     still invoke the command from within the function?
2047
2048 This is why the `command' and `builtin' builtins exist.  The
2049 `command' builtin executes the command supplied as its first
2050 argument, skipping over any function defined with that name.  The
2051 `builtin' builtin executes the builtin command given as its first
2052 argument directly. 
2053
2054 For example, to write a function to replace `cd' that writes the
2055 hostname and current directory to an xterm title bar, use
2056 something like the following:
2057
2058         cd()
2059         {
2060                 builtin cd "$@" && xtitle "$HOST: $PWD"
2061         }
2062
2063 This could also be written using `command' instead of `builtin';
2064 the version above is marginally more efficient. 
2065
2066 G3) How can I find the value of a shell variable whose name is the value
2067     of another shell variable?
2068
2069 Versions of Bash newer than Bash-2.0 support this directly.  You can use 
2070
2071         ${!var}
2072
2073 For example, the following sequence of commands will echo `z':
2074
2075         var1=var2
2076         var2=z
2077         echo ${!var1}
2078
2079 For sh compatibility, use the `eval' builtin.  The important
2080 thing to remember is that `eval' expands the arguments you give
2081 it again, so you need to quote the parts of the arguments that
2082 you want `eval' to act on. 
2083
2084 For example, this expression prints the value of the last positional
2085 parameter:
2086
2087         eval echo \"\$\{$#\}\"
2088
2089 The expansion of the quoted portions of this expression will be
2090 deferred until `eval' runs, while the `$#' will be expanded
2091 before `eval' is executed.  In versions of bash later than bash-2.0,
2092
2093         echo ${!#}
2094
2095 does the same thing.
2096
2097 This is not the same thing as ksh93 `nameref' variables, though the syntax
2098 is similar.  I may add namerefs in a future bash version.
2099
2100 G4) How can I make the bash `time' reserved word print timing output that
2101      looks like the output from my system's /usr/bin/time?
2102
2103 The bash command timing code looks for a variable `TIMEFORMAT' and
2104 uses its value as a format string to decide how to display the
2105 timing statistics.
2106
2107 The value of TIMEFORMAT is a string with `%' escapes expanded in a
2108 fashion similar in spirit to printf(3).  The manual page explains
2109 the meanings of the escape sequences in the format string.
2110
2111 If TIMEFORMAT is not set, bash acts as if the following assignment had
2112 been performed:
2113
2114         TIMEFORMAT=$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
2115
2116 The POSIX.2 default time format (used by `time -p command') is
2117
2118         TIMEFORMAT=$'real %2R\nuser %2U\nsys %2S'
2119
2120 The BSD /usr/bin/time format can be emulated with:
2121
2122         TIMEFORMAT=$'\t%1R real\t%1U user\t%1S sys'
2123
2124 The System V /usr/bin/time format can be emulated with:
2125
2126         TIMEFORMAT=$'\nreal\t%1R\nuser\t%1U\nsys\t%1S'
2127
2128 The ksh format can be emulated with:
2129
2130         TIMEFORMAT=$'\nreal\t%2lR\nuser\t%2lU\nsys\t%2lS'
2131
2132 G5) How do I get the current directory into my prompt?
2133
2134 Bash provides a number of backslash-escape sequences which are expanded
2135 when the prompt string (PS1 or PS2) is displayed.  The full list is in
2136 the manual page.
2137
2138 The \w expansion gives the full pathname of the current directory, with
2139 a tilde (`~') substituted for the current value of $HOME.  The \W
2140 expansion gives the basename of the current directory.  To put the full
2141 pathname of the current directory into the path without any tilde
2142 subsitution, use $PWD.  Here are some examples:
2143
2144         PS1='\w$ '      # current directory with tilde
2145         PS1='\W$ '      # basename of current directory
2146         PS1='$PWD$ '    # full pathname of current directory
2147
2148 The single quotes are important in the final example to prevent $PWD from
2149 being expanded when the assignment to PS1 is performed.
2150
2151 G6) How can I rename "*.foo" to "*.bar"?
2152
2153 Use the pattern removal functionality described in D3.  The following `for'
2154 loop will do the trick:
2155
2156         for f in *.foo; do
2157                 mv $f ${f%foo}bar
2158         done
2159
2160 G7) How can I translate a filename from uppercase to lowercase?
2161
2162 The script examples/functions/lowercase, originally written by John DuBois,
2163 will do the trick.  The converse is left as an exercise.
2164
2165 G8) How can I write a filename expansion (globbing) pattern that will match
2166     all files in the current directory except "." and ".."?
2167
2168 You must have set the `extglob' shell option using `shopt -s extglob' to use
2169 this:
2170
2171         echo .!(.|) *
2172
2173 A solution that works without extended globbing is given in the Unix Shell
2174 FAQ, posted periodically to comp.unix.shell.  It's a variant of
2175
2176         echo .[!.]* ..?* *
2177
2178 (The ..?* catches files with names of three or more characters beginning
2179 with `..')
2180
2181 Section H:  Where do I go from here?
2182
2183 H1) How do I report bugs in bash, and where should I look for fixes and
2184     advice?
2185
2186 Use the `bashbug' script to report bugs.  It is built and
2187 installed at the same time as bash.  It provides a standard
2188 template for reporting a problem and automatically includes
2189 information about your configuration and build environment. 
2190
2191 `bashbug' sends its reports to bug-bash@gnu.org, which
2192 is a large mailing list gatewayed to the usenet newsgroup gnu.bash.bug. 
2193
2194 Bug fixes, answers to questions, and announcements of new releases
2195 are all posted to gnu.bash.bug.  Discussions concerning bash features
2196 and problems also take place there.
2197
2198 To reach the bash maintainers directly, send mail to
2199 bash-maintainers@gnu.org.
2200
2201 H2) What kind of bash documentation is there?
2202
2203 First, look in the doc directory in the bash distribution.  It should
2204 contain at least the following files:
2205
2206 bash.1          an extensive, thorough Unix-style manual page
2207 builtins.1      a manual page covering just bash builtin commands
2208 bashref.texi    a reference manual in GNU tex`info format
2209 bashref.info    an info version of the reference manual
2210 FAQ             this file
2211 article.ms      text of an article written for The Linux Journal
2212 readline.3      a man page describing readline
2213
2214 Postscript, HTML, and ASCII files created from the above source are
2215 available in the documentation distribution.
2216
2217 There is additional documentation available for anonymous FTP from host
2218 ftp.cwru.edu in the `pub/bash' directory.
2219
2220 Cameron Newham and Bill Rosenblatt have written a book on bash, published
2221 by O'Reilly and Associates.  The book is based on Bill Rosenblatt's Korn
2222 Shell book.  The title is ``Learning the Bash Shell'', and the ISBN number
2223 of the third edition, published in March, 2005, is 0-596-00965-8.  Look for
2224 it in fine bookstores near you.  This edition of the book has been updated
2225 to cover bash-3.0.
2226
2227 The GNU Bash Reference Manual has been published as a printed book by
2228 Network Theory Ltd (Paperback, ISBN: 0-9541617-7-7, Nov. 2006).  It covers
2229 bash-3.2 and is available from most online bookstores (see
2230 http://www.network-theory.co.uk/bash/manual/ for details).  The publisher
2231 will donate $1 to the Free Software Foundation for each copy sold. 
2232
2233 Arnold Robbins and Nelson Beebe have written ``Classic Shell Scripting'',
2234 published by O'Reilly.  The first edition, with ISBN number 0-596-00595-4,
2235 was published in May, 2005.
2236
2237 Chris F. A. Johnson, a frequent contributor to comp.unix.shell and
2238 gnu.bash.bug, has written ``Shell Scripting Recipes: A Problem-Solution
2239 Approach,'' a new book on shell scripting, concentrating on features of
2240 the POSIX standard helpful to shell script writers.  The first edition from
2241 Apress, with ISBN number 1-59059-471-1, was published in May, 2005.
2242
2243 H3) What's coming in future versions?
2244
2245 These are features I hope to include in a future version of bash.
2246
2247 Rocky Bernstein's bash debugger (support is included with bash-4.0)
2248
2249 H4) What's on the bash `wish list' for future versions?
2250
2251 These are features that may or may not appear in a future version of bash.
2252
2253 breaking some of the shell functionality into embeddable libraries
2254 a module system like zsh's, using dynamic loading like builtins
2255 a bash programmer's guide with a chapter on creating loadable builtins
2256 a better loadable interface to perl with access to the shell builtins and
2257         variables (contributions gratefully accepted)
2258 ksh93-like `nameref' variables
2259 ksh93-like `xx.yy' variables (including some of the .sh.* variables) and
2260         associated disipline functions
2261 Some of the new ksh93 pattern matching operators, like backreferencing
2262
2263 H5) When will the next release appear?
2264
2265 The next version will appear sometime in 2010.  Never make predictions. 
2266
2267 This document is Copyright 1995-2010 by Chester Ramey.
2268
2269 Permission is hereby granted, without written agreement and
2270 without license or royalty fees, to use, copy, and distribute
2271 this document for any purpose, provided that the above copyright
2272 notice appears in all copies of this document and that the
2273 contents of this document remain unaltered.