blob: 87dbb2d0254d4f127991b3eff22241525509042b [file] [log] [blame]
Chet Rameya0c0a002016-09-15 16:59:08 -04001This is the Bash FAQ, version 4.14, for Bash version 4.4.
2
3[THIS FAQ IS NO LONGER MAINTAINED]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004
5This document contains a set of frequently-asked questions concerning
6Bash, the GNU Bourne-Again Shell. Bash is a freely-available command
7interpreter with advanced features for both interactive use and shell
8programming.
9
10Another good source of basic information about shells is the collection
11of FAQ articles periodically posted to comp.unix.shell.
12
13Questions and comments concerning this document should be sent to
Jari Aalto06285672006-10-10 14:15:34 +000014chet.ramey@case.edu.
Jari Aaltoccc6cda1996-12-23 17:02:34 +000015
16This document is available for anonymous FTP with the URL
17
Jari Aaltocce855b1998-04-17 19:52:44 +000018ftp://ftp.cwru.edu/pub/bash/FAQ
Jari Aaltoccc6cda1996-12-23 17:02:34 +000019
Jari Aaltobb706242000-03-17 21:46:59 +000020The Bash home page is http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html
21
Jari Aaltoccc6cda1996-12-23 17:02:34 +000022----------
23Contents:
24
25Section A: The Basics
26
Jari Aaltob72432f1999-02-19 17:11:39 +000027A1) What is it?
28A2) What's the latest version?
29A3) Where can I get it?
30A4) On what machines will bash run?
31A5) Will bash run on operating systems other than Unix?
32A6) How can I build bash with gcc?
33A7) How can I make bash my login shell?
34A8) I just changed my login shell to bash, and now I can't FTP into my
35 machine. Why not?
Jari Aaltob80f6442004-07-27 13:29:18 +000036A9) What's the `POSIX Shell and Utilities standard'?
Jari Aaltob72432f1999-02-19 17:11:39 +000037A10) What is the bash `posix mode'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +000038
39Section B: The latest version
40
Chet Rameyac50fba2014-02-26 09:36:43 -050041B1) What's new in version 4.3?
42B2) Are there any user-visible incompatibilities between bash-4.3 and
Chet Ramey00018032011-11-21 20:51:19 -050043 previous bash versions?
Jari Aaltoccc6cda1996-12-23 17:02:34 +000044
45Section C: Differences from other Unix shells
46
Jari Aaltob72432f1999-02-19 17:11:39 +000047C1) How does bash differ from sh, the Bourne shell?
48C2) How does bash differ from the Korn shell, version ksh88?
49C3) Which new features in ksh-93 are not in bash, and which are?
Jari Aaltoccc6cda1996-12-23 17:02:34 +000050
51Section D: Why does bash do some things differently than other Unix shells?
52
Jari Aaltob72432f1999-02-19 17:11:39 +000053D1) Why does bash run a different version of `command' than
Jari Aaltoccc6cda1996-12-23 17:02:34 +000054 `which command' says it will?
Jari Aaltob72432f1999-02-19 17:11:39 +000055D2) Why doesn't bash treat brace expansions exactly like csh?
56D3) Why doesn't bash have csh variable modifiers?
57D4) How can I make my csh aliases work when I convert to bash?
58D5) How can I pipe standard output and standard error from one command to
Jari Aaltoccc6cda1996-12-23 17:02:34 +000059 another, like csh does with `|&'?
Jari Aaltob72432f1999-02-19 17:11:39 +000060D6) Now that I've converted from ksh to bash, are there equivalents to
Jari Aaltoccc6cda1996-12-23 17:02:34 +000061 ksh features like autoloaded functions and the `whence' command?
62
Jari Aaltobb706242000-03-17 21:46:59 +000063Section E: Why does bash do certain things the way it does?
Jari Aaltoccc6cda1996-12-23 17:02:34 +000064
Jari Aaltob72432f1999-02-19 17:11:39 +000065E1) Why is the bash builtin `test' slightly different from /bin/test?
66E2) Why does bash sometimes say `Broken pipe'?
Jari Aaltobb706242000-03-17 21:46:59 +000067E3) When I have terminal escape sequences in my prompt, why does bash
Jari Aaltoccc6cda1996-12-23 17:02:34 +000068 wrap lines at the wrong column?
Jari Aaltobb706242000-03-17 21:46:59 +000069E4) If I pipe the output of a command into `read variable', why doesn't
Jari Aaltoccc6cda1996-12-23 17:02:34 +000070 the output show up in $variable when the read command finishes?
Jari Aaltobb706242000-03-17 21:46:59 +000071E5) I have a bunch of shell scripts that use backslash-escaped characters
Jari Aaltoccc6cda1996-12-23 17:02:34 +000072 in arguments to `echo'. Bash doesn't interpret these characters. Why
73 not, and how can I make it understand them?
Jari Aaltobb706242000-03-17 21:46:59 +000074E6) Why doesn't a while or for loop get suspended when I type ^Z?
Jari Aalto28ef6c32001-04-06 19:14:31 +000075E7) What about empty for loops in Makefiles?
76E8) Why does the arithmetic evaluation code complain about `08'?
77E9) Why does the pattern matching expression [A-Z]* match files beginning
78 with every letter except `z'?
Jari Aalto7117c2d2002-07-17 14:10:11 +000079E10) Why does `cd //' leave $PWD as `//'?
Jari Aaltob80f6442004-07-27 13:29:18 +000080E11) If I resize my xterm while another program is running, why doesn't bash
81 notice the change?
82E12) Why don't negative offsets in substring expansion work like I expect?
Jari Aalto06285672006-10-10 14:15:34 +000083E13) Why does filename completion misbehave if a colon appears in the filename?
Jari Aalto31859422009-01-12 13:36:28 +000084E14) Why does quoting the pattern argument to the regular expression matching
85 conditional operator (=~) cause matching to stop working?
Chet Ramey00018032011-11-21 20:51:19 -050086E15) Tell me more about the shell compatibility level.
Jari Aaltoccc6cda1996-12-23 17:02:34 +000087
88Section F: Things to watch out for on certain Unix versions
89
Jari Aaltob72432f1999-02-19 17:11:39 +000090F1) Why can't I use command line editing in my `cmdtool'?
91F2) I built bash on Solaris 2. Why do globbing expansions and filename
Jari Aaltoccc6cda1996-12-23 17:02:34 +000092 completion chop off the first few characters of each filename?
Jari Aaltob72432f1999-02-19 17:11:39 +000093F3) Why does bash dump core after I interrupt username completion or
Jari Aaltoccc6cda1996-12-23 17:02:34 +000094 `~user' tilde expansion on a machine running NIS?
Jari Aaltob72432f1999-02-19 17:11:39 +000095F4) I'm running SVR4.2. Why is the line erased every time I type `@'?
96F5) Why does bash report syntax errors when my C News scripts use a
Jari Aaltoccc6cda1996-12-23 17:02:34 +000097 redirection before a subshell command?
Jari Aaltobb706242000-03-17 21:46:59 +000098F6) Why can't I use vi-mode editing on Red Hat Linux 6.1?
Jari Aalto7117c2d2002-07-17 14:10:11 +000099F7) Why do bash-2.05a and bash-2.05b fail to compile `printf.def' on
100 HP/UX 11.x?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000101
Jari Aaltobb706242000-03-17 21:46:59 +0000102Section G: How can I get bash to do certain common things?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000103
Jari Aaltobb706242000-03-17 21:46:59 +0000104G1) How can I get bash to read and display eight-bit characters?
105G2) How do I write a function `x' to replace builtin command `x', but
106 still invoke the command from within the function?
107G3) How can I find the value of a shell variable whose name is the value
108 of another shell variable?
109G4) How can I make the bash `time' reserved word print timing output that
110 looks like the output from my system's /usr/bin/time?
111G5) How do I get the current directory into my prompt?
112G6) How can I rename "*.foo" to "*.bar"?
113G7) How can I translate a filename from uppercase to lowercase?
114G8) How can I write a filename expansion (globbing) pattern that will match
115 all files in the current directory except "." and ".."?
116
117Section H: Where do I go from here?
118
119H1) How do I report bugs in bash, and where should I look for fixes and
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000120 advice?
Jari Aaltobb706242000-03-17 21:46:59 +0000121H2) What kind of bash documentation is there?
122H3) What's coming in future versions?
123H4) What's on the bash `wish list'?
124H5) When will the next release appear?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000125
126----------
127Section A: The Basics
128
Jari Aaltob72432f1999-02-19 17:11:39 +0000129A1) What is it?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000130
131Bash is a Unix command interpreter (shell). It is an implementation of
132the Posix 1003.2 shell standard, and resembles the Korn and System V
133shells.
134
135Bash contains a number of enhancements over those shells, both
136for interactive use and shell programming. Features geared
137toward interactive use include command line editing, command
138history, job control, aliases, and prompt expansion. Programming
139features include additional variable expansions, shell
140arithmetic, and a number of variables and options to control
141shell behavior.
142
143Bash was originally written by Brian Fox of the Free Software
144Foundation. The current developer and maintainer is Chet Ramey
145of Case Western Reserve University.
146
Jari Aaltob72432f1999-02-19 17:11:39 +0000147A2) What's the latest version?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000148
Chet Rameya0c0a002016-09-15 16:59:08 -0400149The latest version is 4.3, first made available on 26 February, 2014.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000150
Jari Aaltob72432f1999-02-19 17:11:39 +0000151A3) Where can I get it?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000152
153Bash is the GNU project's shell, and so is available from the
Jari Aaltob72432f1999-02-19 17:11:39 +0000154master GNU archive site, ftp.gnu.org, and its mirrors. The
Jari Aaltocce855b1998-04-17 19:52:44 +0000155latest version is also available for FTP from ftp.cwru.edu.
Chet Rameyac50fba2014-02-26 09:36:43 -0500156The following URLs tell how to get version 4.3:
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000157
Chet Rameyac50fba2014-02-26 09:36:43 -0500158ftp://ftp.gnu.org/pub/gnu/bash/bash-4.3.tar.gz
159ftp://ftp.cwru.edu/pub/bash/bash-4.3.tar.gz
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000160
161Formatted versions of the documentation are available with the URLs:
162
Chet Rameyac50fba2014-02-26 09:36:43 -0500163ftp://ftp.gnu.org/pub/gnu/bash/bash-doc-4.3.tar.gz
164ftp://ftp.cwru.edu/pub/bash/bash-doc-4.3.tar.gz
Jari Aalto95732b42005-12-07 14:08:12 +0000165
166Any patches for the current version are available with the URL:
167
Chet Rameyac50fba2014-02-26 09:36:43 -0500168ftp://ftp.cwru.edu/pub/bash/bash-4.3-patches/
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000169
Jari Aaltob72432f1999-02-19 17:11:39 +0000170A4) On what machines will bash run?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000171
Jari Aaltob80f6442004-07-27 13:29:18 +0000172Bash has been ported to nearly every version of Unix. All you
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000173should have to do to build it on a machine for which a port
174exists is to type `configure' and then `make'. The build process
Jari Aaltob80f6442004-07-27 13:29:18 +0000175will attempt to discover the version of Unix you have and tailor
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000176itself accordingly, using a script created by GNU autoconf.
177
178More information appears in the file `INSTALL' in the distribution.
179
Jari Aaltof73dda02001-11-13 17:56:06 +0000180The Bash web page (http://cnswww.cns.cwru.edu/~chet/bash/bashtop.html)
181explains how to obtain binary versions of bash for most of the major
182commercial Unix systems.
183
Jari Aaltob72432f1999-02-19 17:11:39 +0000184A5) Will bash run on operating systems other than Unix?
Jari Aaltod166f041997-06-05 14:59:13 +0000185
186Configuration specifics for Unix-like systems such as QNX and
Jari Aaltof73dda02001-11-13 17:56:06 +0000187LynxOS are included in the distribution. Bash-2.05 and later
188versions should compile and run on Minix 2.0 (patches were
189contributed), but I don't believe anyone has built bash-2.x on
190earlier Minix versions yet.
Jari Aaltod166f041997-06-05 14:59:13 +0000191
192Bash has been ported to versions of Windows implementing the Win32
193programming interface. This includes Windows 95 and Windows NT.
Jari Aalto95732b42005-12-07 14:08:12 +0000194The port was done by Cygnus Solutions (now part of Red Hat) as part
195of their CYGWIN project. For more information about the project, see
196http://www.cygwin.com/.
Jari Aaltod166f041997-06-05 14:59:13 +0000197
Jari Aaltob72432f1999-02-19 17:11:39 +0000198Cygnus originally ported bash-1.14.7, and that port was part of their
Jari Aalto95732b42005-12-07 14:08:12 +0000199early GNU-Win32 (the original name) releases. Cygnus has also done
Chet Ramey00018032011-11-21 20:51:19 -0500200ports of bash-3.2 and bash-4.0 to the CYGWIN environment, and both
Jari Aalto17345e52009-02-19 22:21:29 +0000201are available as part of their current release.
Jari Aaltocce855b1998-04-17 19:52:44 +0000202
Jari Aaltob80f6442004-07-27 13:29:18 +0000203Bash-2.05b and later versions should require no local Cygnus changes to
204build and run under CYGWIN.
Jari Aaltocce855b1998-04-17 19:52:44 +0000205
Jari Aaltof73dda02001-11-13 17:56:06 +0000206DJ Delorie has a port of bash-2.x which runs under MS-DOS, as part
Jari Aalto28ef6c32001-04-06 19:14:31 +0000207of the DJGPP project. For more information on the project, see
Jari Aaltod166f041997-06-05 14:59:13 +0000208
209http://www.delorie.com/djgpp/
210
Jari Aalto28ef6c32001-04-06 19:14:31 +0000211I have been told that the original DJGPP port was done by Daisuke Aoyama.
212
Jari Aaltof73dda02001-11-13 17:56:06 +0000213Mark Elbrecht <snowball3@bigfoot.com> has sent me notice that bash-2.04
214is available for DJGPP V2. The files are available as:
Jari Aaltod166f041997-06-05 14:59:13 +0000215
Jari Aaltof73dda02001-11-13 17:56:06 +0000216ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204b.zip binary
217ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204d.zip documentation
218ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh204s.zip source
Jari Aaltod166f041997-06-05 14:59:13 +0000219
Jari Aaltob80f6442004-07-27 13:29:18 +0000220Mark began to work with bash-2.05, but I don't know the current status.
Jari Aaltobb706242000-03-17 21:46:59 +0000221
Jari Aaltob80f6442004-07-27 13:29:18 +0000222Bash-3.0 compiles and runs with no modifications under Microsoft's Services
Jari Aalto95732b42005-12-07 14:08:12 +0000223for Unix (SFU), once known as Interix. I do not anticipate any problems
Chet Rameyac50fba2014-02-26 09:36:43 -0500224with building bash-4.2 and later, but will gladly accept any patches that
225are needed.
Jari Aaltobb706242000-03-17 21:46:59 +0000226
Jari Aaltob72432f1999-02-19 17:11:39 +0000227A6) How can I build bash with gcc?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000228
229Bash configures to use gcc by default if it is available. Read the
230file INSTALL in the distribution for more information.
231
Jari Aaltob72432f1999-02-19 17:11:39 +0000232A7) How can I make bash my login shell?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000233
234Some machines let you use `chsh' to change your login shell. Other
Jari Aaltocce855b1998-04-17 19:52:44 +0000235systems use `passwd -s' or `passwd -e'. If one of these works for
236you, that's all you need. Note that many systems require the full
237pathname to a shell to appear in /etc/shells before you can make it
238your login shell. For this, you may need the assistance of your
239friendly local system administrator.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000240
241If you cannot do this, you can still use bash as your login shell, but
242you need to perform some tricks. The basic idea is to add a command
243to your login shell's startup file to replace your login shell with
244bash.
245
246For example, if your login shell is csh or tcsh, and you have installed
247bash in /usr/gnu/bin/bash, add the following line to ~/.login:
248
249 if ( -f /usr/gnu/bin/bash ) exec /usr/gnu/bin/bash --login
250
251(the `--login' tells bash that it is a login shell).
252
253It's not a good idea to put this command into ~/.cshrc, because every
254csh you run without the `-f' option, even ones started to run csh scripts,
255reads that file. If you must put the command in ~/.cshrc, use something
256like
257
258 if ( $?prompt ) exec /usr/gnu/bin/bash --login
259
260to ensure that bash is exec'd only when the csh is interactive.
261
Jari Aaltod166f041997-06-05 14:59:13 +0000262If your login shell is sh or ksh, you have to do two things.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000263
Jari Aaltod166f041997-06-05 14:59:13 +0000264First, create an empty file in your home directory named `.bash_profile'.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000265The existence of this file will prevent the exec'd bash from trying to
266read ~/.profile, and re-execing itself over and over again. ~/.bash_profile
Jari Aaltod166f041997-06-05 14:59:13 +0000267is the first file bash tries to read initialization commands from when
268it is invoked as a login shell.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000269
Jari Aaltod166f041997-06-05 14:59:13 +0000270Next, add a line similar to the above to ~/.profile:
271
Jari Aaltob80f6442004-07-27 13:29:18 +0000272 [ -f /usr/gnu/bin/bash ] && [ -x /usr/gnu/bin/bash ] && \
273 exec /usr/gnu/bin/bash --login
Jari Aaltod166f041997-06-05 14:59:13 +0000274
275This will cause login shells to replace themselves with bash running as
276a login shell. Once you have this working, you can copy your initialization
277code from ~/.profile to ~/.bash_profile.
278
Jari Aaltobb706242000-03-17 21:46:59 +0000279I have received word that the recipe supplied above is insufficient for
280machines running CDE. CDE has a maze of twisty little startup files, all
281slightly different.
282
283If you cannot change your login shell in the password file to bash, you
284will have to (apparently) live with CDE using the shell in the password
285file to run its startup scripts. If you have changed your shell to bash,
Jari Aaltof73dda02001-11-13 17:56:06 +0000286there is code in the CDE startup files (on Solaris, at least) that attempts
287to do the right thing. It is, however, often broken, and may require that
288you use the $BASH_ENV trick described below.
Jari Aaltobb706242000-03-17 21:46:59 +0000289
290`dtterm' claims to use $SHELL as the default program to start, so if you
291can change $SHELL in the CDE startup files, you should be able to use bash
292in your terminal windows.
293
294Setting DTSOURCEPROFILE in ~/.dtprofile will cause the `Xsession' program
295to read your login shell's startup files. You may be able to use bash for
296the rest of the CDE programs by setting SHELL to bash in ~/.dtprofile as
297well, but I have not tried this.
298
299You can use the above `exec' recipe to start bash when not logging in with
300CDE by testing the value of the DT variable:
301
302 if [ -n "$DT" ]; then
303 [ -f /usr/gnu/bin/bash ] && exec /usr/gnu/bin/bash --login
304 fi
305
Jari Aaltof73dda02001-11-13 17:56:06 +0000306If CDE starts its shells non-interactively during login, the login shell
307startup files (~/.profile, ~/.bash_profile) will not be sourced at login.
308To get around this problem, append a line similar to the following to your
309~/.dtprofile:
310
311 BASH_ENV=${HOME}/.bash_profile ; export BASH_ENV
312
313and add the following line to the beginning of ~/.bash_profile:
314
315 unset BASH_ENV
Jari Aaltobb706242000-03-17 21:46:59 +0000316
Jari Aaltob72432f1999-02-19 17:11:39 +0000317A8) I just changed my login shell to bash, and now I can't FTP into my
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000318 machine. Why not?
319
320You must add the full pathname to bash to the file /etc/shells. As
321noted in the answer to the previous question, many systems require
322this before you can make bash your login shell.
323
324Most versions of ftpd use this file to prohibit `special' users
325such as `uucp' and `news' from using FTP.
326
Jari Aaltob80f6442004-07-27 13:29:18 +0000327A9) What's the `POSIX Shell and Utilities standard'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000328
329POSIX is a name originally coined by Richard Stallman for a
330family of open system standards based on UNIX. There are a
331number of aspects of UNIX under consideration for
332standardization, from the basic system services at the system
333call and C library level to applications and tools to system
334administration and management. Each area of standardization is
335assigned to a working group in the 1003 series.
336
Jari Aaltob80f6442004-07-27 13:29:18 +0000337The POSIX Shell and Utilities standard was originally developed by
338IEEE Working Group 1003.2 (POSIX.2). Today it has been merged with
339the original 1003.1 Working Group and is maintained by the Austin
340Group (a joint working group of the IEEE, The Open Group and
341ISO/IEC SC22/WG15). Today the Shell and Utilities are a volume
342within the set of documents that make up IEEE Std 1003.1-2001, and
343thus now the former POSIX.2 (from 1992) is now part of the current
344POSIX.1 standard (POSIX 1003.1-2001).
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000345
Jari Aaltob80f6442004-07-27 13:29:18 +0000346The Shell and Utilities volume concentrates on the command
347interpreter interface and utility programs commonly executed from
348the command line or by other programs. The standard is freely
349available on the web at http://www.UNIX-systems.org/version3/ .
350Work continues at the Austin Group on maintenance issues; see
351http://www.opengroup.org/austin/ to join the discussions.
352
353Bash is concerned with the aspects of the shell's behavior defined
354by the POSIX Shell and Utilities volume. The shell command
355language has of course been standardized, including the basic flow
356control and program execution constructs, I/O redirection and
357pipelining, argument handling, variable expansion, and quoting.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000358
359The `special' builtins, which must be implemented as part of the
360shell to provide the desired functionality, are specified as
361being part of the shell; examples of these are `eval' and
Jari Aaltob80f6442004-07-27 13:29:18 +0000362`export'. Other utilities appear in the sections of POSIX not
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000363devoted to the shell which are commonly (and in some cases must
364be) implemented as builtin commands, such as `read' and `test'.
Jari Aaltob80f6442004-07-27 13:29:18 +0000365POSIX also specifies aspects of the shell's interactive
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000366behavior as part of the UPE, including job control and command
367line editing. Only vi-style line editing commands have been
368standardized; emacs editing commands were left out due to
369objections.
370
Jari Aaltob80f6442004-07-27 13:29:18 +0000371The latest version of the POSIX Shell and Utilities standard is
372available (now updated to the 2004 Edition) as part of the Single
373UNIX Specification Version 3 at
Jari Aaltof73dda02001-11-13 17:56:06 +0000374
Jari Aaltob80f6442004-07-27 13:29:18 +0000375http://www.UNIX-systems.org/version3/
Jari Aalto7117c2d2002-07-17 14:10:11 +0000376
Jari Aaltob72432f1999-02-19 17:11:39 +0000377A10) What is the bash `posix mode'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000378
Jari Aaltob80f6442004-07-27 13:29:18 +0000379Although bash is an implementation of the POSIX shell
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000380specification, there are areas where the bash default behavior
381differs from that spec. The bash `posix mode' changes the bash
382behavior in these areas so that it obeys the spec more closely.
383
Jari Aalto7117c2d2002-07-17 14:10:11 +0000384Posix mode is entered by starting bash with the --posix or
385'-o posix' option or executing `set -o posix' after bash is running.
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000386
387The specific aspects of bash which change when posix mode is
Jari Aalto7117c2d2002-07-17 14:10:11 +0000388active are listed in the file POSIX in the bash distribution.
389They are also listed in a section in the Bash Reference Manual
390(from which that file is generated).
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000391
392Section B: The latest version
393
Chet Rameyac50fba2014-02-26 09:36:43 -0500394B1) What's new in version 4.3?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000395
Chet Rameyac50fba2014-02-26 09:36:43 -0500396Bash-4.3 is the third revision to the fourth major release of bash.
Jari Aalto17345e52009-02-19 22:21:29 +0000397
Chet Rameyac50fba2014-02-26 09:36:43 -0500398Bash-4.3 contains the following new features (see the manual page for
399complete descriptions and the CHANGES and NEWS files in the bash-4.3
Jari Aalto17345e52009-02-19 22:21:29 +0000400distribution):
401
Chet Rameyac50fba2014-02-26 09:36:43 -0500402o The `helptopic' completion action now maps to all the help topics, not just
403 the shell builtins.
404
405o The `help' builtin no longer does prefix substring matching first, so
406 `help read' does not match `readonly', but will do it if exact string
407 matching fails.
408
409o The shell can be compiled to not display a message about processes that
410 terminate due to SIGTERM.
411
412o Non-interactive shells now react to the setting of checkwinsize and set
413 LINES and COLUMNS after a foreground job exits.
414
415o There is a new shell option, `globasciiranges', which, when set to on,
416 forces globbing range comparisons to use character ordering as if they
417 were run in the C locale.
418
419o There is a new shell option, `direxpand', which makes filename completion
420 expand variables in directory names in the way bash-4.1 did.
421
422o In Posix mode, the `command' builtin does not change whether or not a
423 builtin it shadows is treated as an assignment builtin.
424
425o The `return' and `exit' builtins accept negative exit status arguments.
426
427o The word completion code checks whether or not a filename containing a
428 shell variable expands to a directory name and appends `/' to the word
429 as appropriate. The same code expands shell variables in command names
430 when performing command completion.
431
432o In Posix mode, it is now an error to attempt to define a shell function
433 with the same name as a Posix special builtin.
434
435o When compiled for strict Posix conformance, history expansion is disabled
436 by default.
437
438o The history expansion character (!) does not cause history expansion when
439 followed by the closing quote in a double-quoted string.
440
441o `complete' and its siblings compgen/compopt now takes a new `-o noquote'
442 option to inhibit quoting of the completions.
443
444o Setting HISTSIZE to a value less than zero causes the history list to be
445 unlimited (setting it 0 zero disables the history list).
446
447o Setting HISTFILESIZE to a value less than zero causes the history file size
448 to be unlimited (setting it to 0 causes the history file to be truncated
449 to zero size).
450
451o The `read' builtin now skips NUL bytes in the input.
452
453o There is a new `bind -X' option to print all key sequences bound to Unix
454 commands.
455
456o When in Posix mode, `read' is interruptible by a trapped signal. After
457 running the trap handler, read returns 128+signal and throws away any
458 partially-read input.
459
460o The command completion code skips whitespace and assignment statements
461 before looking for the command name word to be completed.
462
463o The build process has a new mechanism for constructing separate help files
464 that better reflects the current set of compilation options.
465
466o The -nt and -ot options to test now work with files with nanosecond
467 timestamp resolution.
468
469o The shell saves the command history in any shell for which history is
470 enabled and HISTFILE is set, not just interactive shells.
471
472o The shell has `nameref' variables and new -n(/+n) options to declare and
473 unset to use them, and a `test -R' option to test for them.
474
475o The shell now allows assigning, referencing, and unsetting elements of
476 indexed arrays using negative subscripts (a[-1]=2, echo ${a[-1]}) which
477 count back from the last element of the array.
478
479o The {x}<word redirection feature now allows words like {array[ind]} and
480 can use variables with special meanings to the shell (e.g., BASH_XTRACEFD).
481
482o There is a new CHILD_MAX special shell variable; its value controls the
483 number of exited child statues the shell remembers.
484
485o There is a new configuration option (--enable-direxpand-default) that
486 causes the `direxpand' shell option to be enabled by default.
487
488o Bash does not do anything special to ensure that the file descriptor
489 assigned to X in {x}<foo remains open after the block containing it
490 completes.
491
492o The `wait' builtin has a new `-n' option to wait for the next child to
493 change status.
494
495o The `printf' %(...)T format specifier now uses the current time if no
496 argument is supplied.
497
498o There is a new variable, BASH_COMPAT, that controls the current shell
499 compatibility level.
500
501o The `popd' builtin now treats additional arguments as errors.
502
503o The brace expansion code now treats a failed sequence expansion as a
504 simple string and will continue to expand brace terms in the remainder
505 of the word.
506
507o Shells started to run process substitutions now run any trap set on EXIT.
508
509o The fc builtin now interprets -0 as the current command line.
510
511o Completing directory names containing shell variables now adds a trailing
512 slash if the expanded result is a directory.
513
514A short feature history dating back to Bash-2.0:
515
516Bash-4.2 contained the following new features:
517
Chet Ramey495aee42011-11-22 19:11:26 -0500518o `exec -a foo' now sets $0 to `foo' in an executable shell script without a
519 leading #!.
520
521o Subshells begun to execute command substitutions or run shell functions or
522 builtins in subshells do not reset trap strings until a new trap is
523 specified. This allows $(trap) to display the caller's traps and the
524 trap strings to persist until a new trap is set.
525
526o `trap -p' will now show signals ignored at shell startup, though their
527 disposition still cannot be modified.
528
529o $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
530
531o declare/typeset has a new `-g' option, which creates variables in the
532 global scope even when run in a shell function.
533
534o test/[/[[ have a new -v variable unary operator, which returns success if
535 `variable' has been set.
536
537o Posix parsing changes to allow `! time command' and multiple consecutive
538 instances of `!' (which toggle) and `time' (which have no cumulative
539 effect).
540
541o Posix change to allow `time' as a command by itself to print the elapsed
542 user, system, and real times for the shell and its children.
543
544o $((...)) is always parsed as an arithmetic expansion first, instead of as
545 a potential nested command substitution, as Posix requires.
546
547o A new FUNCNEST variable to allow the user to control the maximum shell
548 function nesting (recursive execution) level.
549
550o The mapfile builtin now supplies a third argument to the callback command:
551 the line about to be assigned to the supplied array index.
552
553o The printf builtin has as new %(fmt)T specifier, which allows time values
554 to use strftime-like formatting.
555
556o There is a new `compat41' shell option.
557
558o The cd builtin has a new Posix-mandated `-e' option.
559
560o Negative subscripts to indexed arrays, previously errors, now are treated
561 as offsets from the maximum assigned index + 1.
562
563o Negative length specifications in the ${var:offset:length} expansion,
564 previously errors, are now treated as offsets from the end of the variable.
565
566o Parsing change to allow `time -p --'.
567
568o Posix-mode parsing change to not recognize `time' as a keyword if the
569 following token begins with a `-'. This means no more Posix-mode
570 `time -p'. Posix interpretation 267.
571
572o There is a new `lastpipe' shell option that runs the last command of a
573 pipeline in the current shell context. The lastpipe option has no
574 effect if job control is enabled.
575
576o History expansion no longer expands the `$!' variable expansion.
577
578o Posix mode shells no longer exit if a variable assignment error occurs
579 with an assignment preceding a command that is not a special builtin.
580
581o Non-interactive mode shells exit if -u is enabled an an attempt is made
582 to use an unset variable with the % or # expansions, the `//', `^', or
583 `,' expansions, or the parameter length expansion.
584
585o Posix-mode shells use the argument passed to `.' as-is if a $PATH search
586 fails, effectively searching the current directory. Posix-2008 change.
587
588A short feature history dating back to Bash-2.0:
589
590Bash-4.1 contained the following new features:
591
Chet Ramey00018032011-11-21 20:51:19 -0500592o Here-documents within $(...) command substitutions may once more be
593 delimited by the closing right paren, instead of requiring a newline.
594
595o Bash's file status checks (executable, readable, etc.) now take file
596 system ACLs into account on file systems that support them.
597
598o Bash now passes environment variables with names that are not valid
599 shell variable names through into the environment passed to child
600 processes.
601
602o The `execute-unix-command' readline function now attempts to clear and
603 reuse the current line rather than move to a new one after the command
604 executes.
605
606o `printf -v' can now assign values to array indices.
607
608o New `complete -E' and `compopt -E' options that work on the "empty"
609 completion: completion attempted on an empty command line.
610
611o New complete/compgen/compopt -D option to define a `default' completion:
612 a completion to be invoked on command for which no completion has been
613 defined. If this function returns 124, programmable completion is
614 attempted again, allowing a user to dynamically build a set of completions
615 as completion is attempted by having the default completion function
616 install individual completion functions each time it is invoked.
617
618o When displaying associative arrays, subscripts are now quoted.
619
620o Changes to dabbrev-expand to make it more `emacs-like': no space appended
621 after matches, completions are not sorted, and most recent history entries
622 are presented first.
623
624o The [[ and (( commands are now subject to the setting of `set -e' and the
625 ERR trap.
626
627o The source/. builtin now removes NUL bytes from the file before attempting
628 to parse commands.
629
630o There is a new configuration option (in config-top.h) that forces bash to
631 forward all history entries to syslog.
632
633o A new variable $BASHOPTS to export shell options settable using `shopt' to
634 child processes.
635
636o There is a new confgure option that forces the extglob option to be
637 enabled by default.
638
639o New variable $BASH_XTRACEFD; when set to an integer bash will write xtrace
640 output to that file descriptor.
641
642o If the optional left-hand-side of a redirection is of the form {var}, the
643 shell assigns the file descriptor used to $var or uses $var as the file
644 descriptor to move or close, depending on the redirection operator.
645
646o The < and > operators to the [[ conditional command now do string
647 comparison according to the current locale.
648
649o Programmable completion now uses the completion for `b' instead of `a'
650 when completion is attempted on a line like: a $(b c.
651
652o Force extglob on temporarily when parsing the pattern argument to
653 the == and != operators to the [[ command, for compatibility.
654
655o Changed the behavior of interrupting the wait builtin when a SIGCHLD is
656 received and a trap on SIGCHLD is set to be Posix-mode only.
657
658o The read builtin has a new `-N nchars' option, which reads exactly NCHARS
659 characters, ignoring delimiters like newline.
660
661o The mapfile/readarray builtin no longer stores the commands it invokes via
662 callbacks in the history list.
663
664o There is a new `compat40' shopt option.
665
666o The < and > operators to [[ do string comparisons using the current locale
667 only if the compatibility level is greater than 40 (set to 41 by default).
668
669o New bindable readline function: menu-complete-backward.
670
671o In the readline vi-mode insertion keymap, C-n is now bound to menu-complete
672 by default, and C-p to menu-complete-backward.
673
674o When in readline vi command mode, repeatedly hitting ESC now does nothing,
675 even when ESC introduces a bound key sequence. This is closer to how
676 historical vi behaves.
677
678o New bindable readline function: skip-csi-sequence. Can be used as a
679 default to consume key sequences generated by keys like Home and End
680 without having to bind all keys.
681
682o New bindable readline variable: skip-completed-text, active when
683 completing in the middle of a word. If enabled, it means that characters
684 in the completion that match characters in the remainder of the word are
685 "skipped" rather than inserted into the line.
686
687o The pre-readline-6.0 version of menu completion is available as
688 "old-menu-complete" for users who do not like the readline-6.0 version.
689
690o New bindable readline variable: echo-control-characters. If enabled, and
691 the tty ECHOCTL bit is set, controls the echoing of characters
692 corresponding to keyboard-generated signals.
693
694o New bindable readline variable: enable-meta-key. Controls whether or not
695 readline sends the smm/rmm sequences if the terminal indicates it has a
696 meta key that enables eight-bit characters.
697
Chet Ramey00018032011-11-21 20:51:19 -0500698Bash-4.0 contained the following new features:
699
Jari Aalto17345e52009-02-19 22:21:29 +0000700o When using substring expansion on the positional parameters, a starting
701 index of 0 now causes $0 to be prefixed to the list.
702
703o There is a new variable, $BASHPID, which always returns the process id of
704 the current shell.
705
706o There is a new `autocd' option that, when enabled, causes bash to attempt
707 to `cd' to a directory name that is supplied as the first word of a
708 simple command.
709
710o There is a new `checkjobs' option that causes the shell to check for and
711 report any running or stopped jobs at exit.
712
713o The programmable completion code exports a new COMP_TYPE variable, set to
714 a character describing the type of completion being attempted.
715
716o The programmable completion code exports a new COMP_KEY variable, set to
717 the character that caused the completion to be invoked (e.g., TAB).
718
719o The programmable completion code now uses the same set of characters as
720 readline when breaking the command line into a list of words.
721
722o The block multiplier for the ulimit -c and -f options is now 512 when in
723 Posix mode, as Posix specifies.
724
725o Changed the behavior of the read builtin to save any partial input received
726 in the specified variable when the read builtin times out. This also
727 results in variables specified as arguments to read to be set to the empty
728 string when there is no input available. When the read builtin times out,
729 it returns an exit status greater than 128.
730
731o The shell now has the notion of a `compatibility level', controlled by
732 new variables settable by `shopt'. Setting this variable currently
733 restores the bash-3.1 behavior when processing quoted strings on the rhs
734 of the `=~' operator to the `[[' command.
735
736o The `ulimit' builtin now has new -b (socket buffer size) and -T (number
737 of threads) options.
738
739o There is a new `compopt' builtin that allows completion functions to modify
740 completion options for existing completions or the completion currently
741 being executed.
742
743o The `read' builtin has a new -i option which inserts text into the reply
744 buffer when using readline.
745
746o A new `-E' option to the complete builtin allows control of the default
747 behavior for completion on an empty line.
748
749o There is now limited support for completing command name words containing
750 globbing characters.
751
752o The `help' builtin now has a new -d option, to display a short description,
753 and a -m option, to print help information in a man page-like format.
754
755o There is a new `mapfile' builtin to populate an array with lines from a
756 given file.
757
758o If a command is not found, the shell attempts to execute a shell function
759 named `command_not_found_handle', supplying the command words as the
760 function arguments.
761
762o There is a new shell option: `globstar'. When enabled, the globbing code
763 treats `**' specially -- it matches all directories (and files within
764 them, when appropriate) recursively.
765
766o There is a new shell option: `dirspell'. When enabled, the filename
767 completion code performs spelling correction on directory names during
768 completion.
769
770o The `-t' option to the `read' builtin now supports fractional timeout
771 values.
772
773o Brace expansion now allows zero-padding of expanded numeric values and
774 will add the proper number of zeroes to make sure all values contain the
775 same number of digits.
776
777o There is a new bash-specific bindable readline function: `dabbrev-expand'.
778 It uses menu completion on a set of words taken from the history list.
779
780o The command assigned to a key sequence with `bind -x' now sets two new
781 variables in the environment of the executed command: READLINE_LINE_BUFFER
782 and READLINE_POINT. The command can change the current readline line
783 and cursor position by modifying READLINE_LINE_BUFFER and READLINE_POINT,
784 respectively.
785
786o There is a new >>& redirection operator, which appends the standard output
787 and standard error to the named file.
788
789o The parser now understands `|&' as a synonym for `2>&1 |', which redirects
790 the standard error for a command through a pipe.
791
792o The new `;&' case statement action list terminator causes execution to
793 continue with the action associated with the next pattern in the
794 statement rather than terminating the command.
795
796o The new `;;&' case statement action list terminator causes the shell to
797 test the next set of patterns after completing execution of the current
798 action, rather than terminating the command.
799
800o The shell understands a new variable: PROMPT_DIRTRIM. When set to an
801 integer value greater than zero, prompt expansion of \w and \W will
802 retain only that number of trailing pathname components and replace
803 the intervening characters with `...'.
804
805o There are new case-modifying word expansions: uppercase (^[^]) and
806 lowercase (,[,]). They can work on either the first character or
807 array element, or globally. They accept an optional shell pattern
808 that determines which characters to modify. There is an optionally-
809 configured feature to include capitalization operators.
810
811o The shell provides associative array variables, with the appropriate
812 support to create, delete, assign values to, and expand them.
813
814o The `declare' builtin now has new -l (convert value to lowercase upon
815 assignment) and -u (convert value to uppercase upon assignment) options.
816 There is an optionally-configurable -c option to capitalize a value at
817 assignment.
818
819o There is a new `coproc' reserved word that specifies a coprocess: an
820 asynchronous command run with two pipes connected to the creating shell.
821 Coprocs can be named. The input and output file descriptors and the
822 PID of the coprocess are available to the calling shell in variables
823 with coproc-specific names.
824
825o A value of 0 for the -t option to `read' now returns success if there is
826 input available to be read from the specified file descriptor.
827
828o CDPATH and GLOBIGNORE are ignored when the shell is running in privileged
829 mode.
830
831o New bindable readline functions shell-forward-word and shell-backward-word,
832 which move forward and backward words delimited by shell metacharacters
833 and honor shell quoting.
834
835o New bindable readline functions shell-backward-kill-word and shell-kill-word
836 which kill words backward and forward, but use the same word boundaries
837 as shell-forward-word and shell-backward-word.
838
Jari Aalto17345e52009-02-19 22:21:29 +0000839Bash-3.2 contained the following new features:
Jari Aalto06285672006-10-10 14:15:34 +0000840
841o Bash-3.2 now checks shell scripts for NUL characters rather than non-printing
842 characters when deciding whether or not a script is a binary file.
843
844o Quoting the string argument to the [[ command's =~ (regexp) operator now
845 forces string matching, as with the other pattern-matching operators.
846
Jari Aalto06285672006-10-10 14:15:34 +0000847Bash-3.1 contained the following new features:
Jari Aaltof73dda02001-11-13 17:56:06 +0000848
Jari Aalto95732b42005-12-07 14:08:12 +0000849o Bash-3.1 may now be configured and built in a mode that enforces strict
850 POSIX compliance.
851
852o The `+=' assignment operator, which appends to the value of a string or
853 array variable, has been implemented.
854
855o It is now possible to ignore case when matching in contexts other than
856 filename generation using the new `nocasematch' shell option.
857
Jari Aalto95732b42005-12-07 14:08:12 +0000858Bash-3.0 contained the following new features:
Jari Aaltobb706242000-03-17 21:46:59 +0000859
Jari Aaltob80f6442004-07-27 13:29:18 +0000860o Features to support the bash debugger have been implemented, and there
861 is a new `extdebug' option to turn the non-default options on
862
863o HISTCONTROL is now a colon-separated list of options and has been
864 extended with a new `erasedups' option that will result in only one
865 copy of a command being kept in the history list
866
867o Brace expansion has been extended with a new {x..y} form, producing
868 sequences of digits or characters
869
870o Timestamps are now kept with history entries, with an option to save
871 and restore them from the history file; there is a new HISTTIMEFORMAT
872 variable describing how to display the timestamps when listing history
873 entries
874
875o The `[[' command can now perform extended regular expression (egrep-like)
876 matching, with matched subexpressions placed in the BASH_REMATCH array
877 variable
878
879o A new `pipefail' option causes a pipeline to return a failure status if
880 any command in it fails
881
882o The `jobs', `kill', and `wait' builtins now accept job control notation
883 in their arguments even if job control is not enabled
884
885o The `gettext' package and libintl have been integrated, and the shell
886 messages may be translated into other languages
887
Jari Aaltob80f6442004-07-27 13:29:18 +0000888Bash-2.05b introduced the following new features:
889
Jari Aalto7117c2d2002-07-17 14:10:11 +0000890o support for multibyte characters has been added to both bash and readline
891
892o the DEBUG trap is now run *before* simple commands, ((...)) commands,
893 [[...]] conditional commands, and for ((...)) loops
894
895o the shell now performs arithmetic in the largest integer size the machine
896 supports (intmax_t)
897
898o there is a new \D{...} prompt expansion; passes the `...' to strftime(3)
899 and inserts the result into the expanded prompt
900
901o there is a new `here-string' redirection operator: <<< word
902
903o when displaying variables, function attributes and definitions are shown
904 separately, allowing them to be re-used as input (attempting to re-use
905 the old output would result in syntax errors).
906
907o `read' has a new `-u fd' option to read from a specified file descriptor
908
909o the bash debugger in examples/bashdb has been modified to work with the
910 new DEBUG trap semantics, the command set has been made more gdb-like,
911 and the changes to $LINENO make debugging functions work better
912
913o the expansion of $LINENO inside a shell function is only relative to the
914 function start if the shell is interactive -- if the shell is running a
915 script, $LINENO expands to the line number in the script. This is as
916 POSIX-2001 requires
917
Jari Aalto7117c2d2002-07-17 14:10:11 +0000918Bash-2.05a introduced the following new features:
919
Jari Aaltof73dda02001-11-13 17:56:06 +0000920o The `printf' builtin has undergone major work
921
922o There is a new read-only `shopt' option: login_shell, which is set by
923 login shells and unset otherwise
924
925o New `\A' prompt string escape sequence; expanding to time in 24-hour
926 HH:MM format
927
928o New `-A group/-g' option to complete and compgen; goes group name
929 completion
930
931o New [+-]O invocation option to set and unset `shopt' options at startup
932
933o ksh-like `ERR' trap
934
935o `for' loops now allow empty word lists after the `in' reserved word
936
937o new `hard' and `soft' arguments for the `ulimit' builtin
938
939o Readline can be configured to place the user at the same point on the line
940 when retrieving commands from the history list
941
942o Readline can be configured to skip `hidden' files (filenames with a leading
943 `.' on Unix) when performing completion
944
Jari Aaltof73dda02001-11-13 17:56:06 +0000945Bash-2.05 introduced the following new features:
946
Jari Aalto28ef6c32001-04-06 19:14:31 +0000947o This version has once again reverted to using locales and strcoll(3) when
948 processing pattern matching bracket expressions, as POSIX requires.
949o Added a new `--init-file' invocation argument as a synonym for `--rcfile',
950 per the new GNU coding standards.
951o The /dev/tcp and /dev/udp redirections now accept service names as well as
952 port numbers.
953o `complete' and `compgen' now take a `-o value' option, which controls some
954 of the aspects of that compspec. Valid values are:
955
956 default - perform bash default completion if programmable
957 completion produces no matches
958 dirnames - perform directory name completion if programmable
959 completion produces no matches
960 filenames - tell readline that the compspec produces filenames,
961 so it can do things like append slashes to
962 directory names and suppress trailing spaces
963o A new loadable builtin, realpath, which canonicalizes and expands symlinks
964 in pathname arguments.
965o When `set' is called without options, it prints function defintions in a
966 way that allows them to be reused as input. This affects `declare' and
967 `declare -p' as well. This only happens when the shell is not in POSIX
968 mode, since POSIX.2 forbids this behavior.
969
Jari Aalto28ef6c32001-04-06 19:14:31 +0000970Bash-2.04 introduced the following new features:
971
Jari Aaltobb706242000-03-17 21:46:59 +0000972o Programmable word completion with the new `complete' and `compgen' builtins;
973 examples are provided in examples/complete/complete-examples
974o `history' has a new `-d' option to delete a history entry
975o `bind' has a new `-x' option to bind key sequences to shell commands
976o The prompt expansion code has new `\j' and `\l' escape sequences
Jari Aalto28ef6c32001-04-06 19:14:31 +0000977o The `no_empty_cmd_completion' shell option, if enabled, inhibits
Jari Aaltobb706242000-03-17 21:46:59 +0000978 command completion when TAB is typed on an empty line
979o `help' has a new `-s' option to print a usage synopsis
980o New arithmetic operators: var++, var--, ++var, --var, expr1,expr2 (comma)
981o New ksh93-style arithmetic for command:
982 for ((expr1 ; expr2; expr3 )); do list; done
983o `read' has new options: `-t', `-n', `-d', `-s'
984o The redirection code handles several filenames specially: /dev/fd/N,
985 /dev/stdin, /dev/stdout, /dev/stderr
986o The redirection code now recognizes /dev/tcp/HOST/PORT and
987 /dev/udp/HOST/PORT and tries to open a TCP or UDP socket, respectively,
988 to the specified port on the specified host
989o The ${!prefix*} expansion has been implemented
990o A new FUNCNAME variable, which expands to the name of a currently-executing
991 function
992o The GROUPS variable is no longer readonly
993o A new shopt `xpg_echo' variable, to control the behavior of echo with
994 respect to backslash-escape sequences at runtime
995o The NON_INTERACTIVE_LOGIN_SHELLS #define has returned
996
Jari Aalto28ef6c32001-04-06 19:14:31 +0000997The version of Readline released with Bash-2.04, Readline-4.1, had several
Jari Aaltobb706242000-03-17 21:46:59 +0000998new features as well:
999
1000o Parentheses matching is always compiled into readline, and controllable
1001 with the new `blink-matching-paren' variable
1002o The history-search-forward and history-search-backward functions now leave
1003 point at the end of the line when the search string is empty, like
1004 reverse-search-history, and forward-search-history
1005o A new function for applications: rl_on_new_line_with_prompt()
1006o New variables for applications: rl_already_prompted, and rl_gnu_readline_p
1007
1008
Jari Aaltobb706242000-03-17 21:46:59 +00001009Bash-2.03 had very few new features, in keeping with the convention
Jari Aaltob72432f1999-02-19 17:11:39 +00001010that odd-numbered releases provide mainly bug fixes. A number of new
1011features were added to Readline, mostly at the request of the Cygnus
1012folks.
1013
Jari Aaltobb706242000-03-17 21:46:59 +00001014A new shopt option, `restricted_shell', so that startup files can test
Jari Aaltob72432f1999-02-19 17:11:39 +00001015 whether or not the shell was started in restricted mode
Jari Aaltobb706242000-03-17 21:46:59 +00001016Filename generation is now performed on the words between ( and ) in
Jari Aaltob72432f1999-02-19 17:11:39 +00001017 compound array assignments (this is really a bug fix)
1018OLDPWD is now auto-exported, as POSIX.2 requires
1019ENV and BASH_ENV are read-only variables in a restricted shell
1020Bash may now be linked against an already-installed Readline library,
1021 as long as the Readline library is version 4 or newer
1022All shells begun with the `--login' option will source the login shell
1023 startup files, even if the shell is not interactive
1024
Jari Aaltobb706242000-03-17 21:46:59 +00001025There were lots of changes to the version of the Readline library released
Jari Aaltob72432f1999-02-19 17:11:39 +00001026along with Bash-2.03. For a complete list of the changes, read the file
1027CHANGES in the Bash-2.03 distribution.
1028
1029Bash-2.02 contained the following new features:
Jari Aaltocce855b1998-04-17 19:52:44 +00001030
1031a new version of malloc (based on the old GNU malloc code in previous
1032 bash versions) that is more page-oriented, more conservative
1033 with memory usage, does not `orphan' large blocks when they
1034 are freed, is usable on 64-bit machines, and has allocation
1035 checking turned on unconditionally
1036POSIX.2-style globbing character classes ([:alpha:], [:alnum:], etc.)
1037POSIX.2-style globbing equivalence classes
1038POSIX.2-style globbing collating symbols
1039the ksh [[...]] extended conditional command
1040the ksh egrep-style extended pattern matching operators
1041a new `printf' builtin
1042the ksh-like $(<filename) command substitution, which is equivalent to
1043 $(cat filename)
1044new tilde prefixes that expand to directories from the directory stack
1045new `**' arithmetic operator to do exponentiation
1046case-insensitive globbing (filename expansion)
1047menu completion a la tcsh
1048`magic-space' history expansion function like tcsh
1049the readline inputrc `language' has a new file inclusion directive ($include)
1050
1051Bash-2.01 contained only a few new features:
Jari Aaltod166f041997-06-05 14:59:13 +00001052
1053new `GROUPS' builtin array variable containing the user's group list
1054new bindable readline commands: history-and-alias-expand-line and
1055 alias-expand-line
1056
Jari Aaltocce855b1998-04-17 19:52:44 +00001057Bash-2.0 contained extensive changes and new features from bash-1.14.7.
Jari Aaltod166f041997-06-05 14:59:13 +00001058Here's a short list:
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001059
1060new `time' reserved word to time pipelines, shell builtins, and
1061 shell functions
1062one-dimensional arrays with a new compound assignment statement,
1063 appropriate expansion constructs and modifications to some
1064 of the builtins (read, declare, etc.) to use them
1065new quoting syntaxes for ANSI-C string expansion and locale-specific
1066 string translation
1067new expansions to do substring extraction, pattern replacement, and
1068 indirect variable expansion
1069new builtins: `disown' and `shopt'
1070new variables: HISTIGNORE, SHELLOPTS, PIPESTATUS, DIRSTACK, GLOBIGNORE,
1071 MACHTYPE, BASH_VERSINFO
1072special handling of many unused or redundant variables removed
1073 (e.g., $notify, $glob_dot_filenames, $no_exit_on_failed_exec)
1074dynamic loading of new builtin commands; many loadable examples provided
1075new prompt expansions: \a, \e, \n, \H, \T, \@, \v, \V
1076history and aliases available in shell scripts
1077new readline variables: enable-keypad, mark-directories, input-meta,
1078 visible-stats, disable-completion, comment-begin
1079new readline commands to manipulate the mark and operate on the region
1080new readline emacs mode commands and bindings for ksh-88 compatibility
1081updated and extended builtins
1082new DEBUG trap
1083expanded (and now documented) restricted shell mode
1084
1085implementation stuff:
1086autoconf-based configuration
1087nearly all of the bugs reported since version 1.14 have been fixed
1088most builtins converted to use builtin `getopt' for consistency
1089most builtins use -p option to display output in a reusable form
1090 (for consistency)
1091grammar tighter and smaller (66 reduce-reduce conflicts gone)
1092lots of code now smaller and faster
1093test suite greatly expanded
1094
Chet Rameyac50fba2014-02-26 09:36:43 -05001095B2) Are there any user-visible incompatibilities between bash-4.3 and
Chet Ramey00018032011-11-21 20:51:19 -05001096 previous bash versions?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001097
Chet Rameyac50fba2014-02-26 09:36:43 -05001098There are a few incompatibilities between version 4.3 and previous
Chet Ramey00018032011-11-21 20:51:19 -05001099versions. They are detailed in the file COMPAT in the bash distribution.
1100That file is not meant to be all-encompassing; send mail to
1101bash-maintainers@gnu.org (or bug-bash@gnu.org if you would like
Chet Ramey495aee42011-11-22 19:11:26 -05001102community discussion) if you find something that's not mentioned there.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001103
1104Section C: Differences from other Unix shells
1105
Jari Aaltob72432f1999-02-19 17:11:39 +00001106C1) How does bash differ from sh, the Bourne shell?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001107
1108This is a non-comprehensive list of features that differentiate bash
1109from the SVR4.2 shell. The bash manual page explains these more
1110completely.
1111
1112Things bash has that sh does not:
1113 long invocation options
Jari Aaltof73dda02001-11-13 17:56:06 +00001114 [+-]O invocation option
Jari Aalto7117c2d2002-07-17 14:10:11 +00001115 -l invocation option
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001116 `!' reserved word to invert pipeline return value
1117 `time' reserved word to time pipelines and shell builtins
1118 the `function' reserved word
Jari Aaltobb706242000-03-17 21:46:59 +00001119 the `select' compound command and reserved word
1120 arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001121 new $'...' and $"..." quoting
1122 the $(...) form of command substitution
Jari Aaltobc4cd231998-07-23 14:37:54 +00001123 the $(<filename) form of command substitution, equivalent to
1124 $(cat filename)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001125 the ${#param} parameter value length operator
1126 the ${!param} indirect parameter expansion operator
Jari Aaltobb706242000-03-17 21:46:59 +00001127 the ${!param*} prefix expansion operator
Jari Aalto7117c2d2002-07-17 14:10:11 +00001128 the ${param:offset[:length]} parameter substring operator
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001129 the ${param/pat[/string]} parameter pattern substitution operator
1130 expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
1131 expansion of positional parameters beyond $9 with ${num}
Jari Aalto17345e52009-02-19 22:21:29 +00001132 variables: BASH, BASHPID, BASH_VERSION, BASH_VERSINFO, UID, EUID, REPLY,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001133 TIMEFORMAT, PPID, PWD, OLDPWD, SHLVL, RANDOM, SECONDS,
1134 LINENO, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE, HOSTNAME,
1135 ENV, PS3, PS4, DIRSTACK, PIPESTATUS, HISTSIZE, HISTFILE,
Jari Aaltobc4cd231998-07-23 14:37:54 +00001136 HISTFILESIZE, HISTCONTROL, HISTIGNORE, GLOBIGNORE, GROUPS,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001137 PROMPT_COMMAND, FCEDIT, FIGNORE, IGNOREEOF, INPUTRC,
Jari Aaltobb706242000-03-17 21:46:59 +00001138 SHELLOPTS, OPTERR, HOSTFILE, TMOUT, FUNCNAME, histchars,
Chet Ramey00018032011-11-21 20:51:19 -05001139 auto_resume, PROMPT_DIRTRIM, BASHOPTS, BASH_XTRACEFD
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001140 DEBUG trap
Jari Aaltof73dda02001-11-13 17:56:06 +00001141 ERR trap
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001142 variable arrays with new compound assignment syntax
Jari Aalto17345e52009-02-19 22:21:29 +00001143 redirections: <>, &>, >|, <<<, [n]<&word-, [n]>&word-, >>&
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001144 prompt string special char translation and variable expansion
Jari Aaltobb706242000-03-17 21:46:59 +00001145 auto-export of variables in initial environment
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001146 command search finds functions before builtins
1147 bash return builtin will exit a file sourced with `.'
Chet Rameyac50fba2014-02-26 09:36:43 -05001148 builtins: cd -/-L/-P/-@, exec -l/-c/-a, echo -e/-E, hash -d/-l/-p/-t.
Jari Aaltobb706242000-03-17 21:46:59 +00001149 export -n/-f/-p/name=value, pwd -L/-P,
Chet Ramey00018032011-11-21 20:51:19 -05001150 read -e/-p/-a/-t/-n/-d/-s/-u/-i/-N,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001151 readonly -a/-f/name=value, trap -l, set +o,
1152 set -b/-m/-o option/-h/-p/-B/-C/-H/-P,
Chet Rameyac50fba2014-02-26 09:36:43 -05001153 unset -f/-n/-v, ulimit -i/-m/-p/-q/-u/-x,
Jari Aalto7117c2d2002-07-17 14:10:11 +00001154 type -a/-p/-t/-f/-P, suspend -f, kill -n,
Chet Rameyac50fba2014-02-26 09:36:43 -05001155 test -o optname/s1 == s2/s1 < s2/s1 > s2/-nt/-ot/-ef/-O/-G/-S/-R
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001156 bash reads ~/.bashrc for interactive shells, $ENV for non-interactive
1157 bash restricted shell mode is more extensive
1158 bash allows functions and variables with the same name
1159 brace expansion
1160 tilde expansion
1161 arithmetic expansion with $((...)) and `let' builtin
Jari Aaltobc4cd231998-07-23 14:37:54 +00001162 the `[[...]]' extended conditional command
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001163 process substitution
1164 aliases and alias/unalias builtins
1165 local variables in functions and `local' builtin
Jari Aaltobb706242000-03-17 21:46:59 +00001166 readline and command-line editing with programmable completion
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001167 command history and history/fc builtins
1168 csh-like history expansion
Jari Aaltobb706242000-03-17 21:46:59 +00001169 other new bash builtins: bind, command, compgen, complete, builtin,
1170 declare/typeset, dirs, enable, fc, help,
1171 history, logout, popd, pushd, disown, shopt,
Jari Aalto17345e52009-02-19 22:21:29 +00001172 printf, compopt, mapfile
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001173 exported functions
1174 filename generation when using output redirection (command >a*)
Jari Aaltobc4cd231998-07-23 14:37:54 +00001175 POSIX.2-style globbing character classes
1176 POSIX.2-style globbing equivalence classes
1177 POSIX.2-style globbing collating symbols
1178 egrep-like extended pattern matching operators
1179 case-insensitive pattern matching and globbing
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001180 variable assignments preceding commands affect only that command,
1181 even for builtins and functions
Jari Aalto95732b42005-12-07 14:08:12 +00001182 posix mode and strict posix conformance
Jari Aaltobb706242000-03-17 21:46:59 +00001183 redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr,
1184 /dev/tcp/host/port, /dev/udp/host/port
Jari Aaltob80f6442004-07-27 13:29:18 +00001185 debugger support, including `caller' builtin and new variables
1186 RETURN trap
Jari Aalto95732b42005-12-07 14:08:12 +00001187 the `+=' assignment operator
Jari Aalto17345e52009-02-19 22:21:29 +00001188 autocd shell option and behavior
1189 command-not-found hook with command_not_found_handle shell function
1190 globstar shell option and `**' globbing behavior
1191 |& synonym for `2>&1 |'
1192 ;& and ;;& case action list terminators
1193 case-modifying word expansions and variable attributes
1194 associative arrays
1195 coprocesses using the `coproc' reserved word and variables
Chet Ramey00018032011-11-21 20:51:19 -05001196 shell assignment of a file descriptor used in a redirection to a variable
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001197
1198Things sh has that bash does not:
1199 uses variable SHACCT to do shell accounting
1200 includes `stop' builtin (bash can use alias stop='kill -s STOP')
1201 `newgrp' builtin
1202 turns on job control if called as `jsh'
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001203 $TIMEOUT (like bash $TMOUT)
1204 `^' is a synonym for `|'
1205 new SVR4.2 sh builtins: mldmode, priv
1206
1207Implementation differences:
1208 redirection to/from compound commands causes sh to create a subshell
1209 bash does not allow unbalanced quotes; sh silently inserts them at EOF
1210 bash does not mess with signal 11
1211 sh sets (euid, egid) to (uid, gid) if -p not supplied and uid < 100
1212 bash splits only the results of expansions on IFS, using POSIX.2
1213 field splitting rules; sh splits all words on IFS
1214 sh does not allow MAILCHECK to be unset (?)
1215 sh does not allow traps on SIGALRM or SIGCHLD
1216 bash allows multiple option arguments when invoked (e.g. -x -v);
1217 sh allows only a single option argument (`sh -x -v' attempts
Jari Aaltod166f041997-06-05 14:59:13 +00001218 to open a file named `-v', and, on SunOS 4.1.4, dumps core.
Jari Aaltob72432f1999-02-19 17:11:39 +00001219 On Solaris 2.4 and earlier versions, sh goes into an infinite
1220 loop.)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001221 sh exits a script if any builtin fails; bash exits only if one of
1222 the POSIX.2 `special' builtins fails
1223
Jari Aaltob72432f1999-02-19 17:11:39 +00001224C2) How does bash differ from the Korn shell, version ksh88?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001225
1226Things bash has or uses that ksh88 does not:
1227 long invocation options
Jari Aaltof73dda02001-11-13 17:56:06 +00001228 [-+]O invocation option
Jari Aalto7117c2d2002-07-17 14:10:11 +00001229 -l invocation option
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001230 `!' reserved word
Jari Aaltobb706242000-03-17 21:46:59 +00001231 arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
Jari Aalto7117c2d2002-07-17 14:10:11 +00001232 arithmetic in largest machine-supported size (intmax_t)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001233 posix mode and posix conformance
1234 command hashing
1235 tilde expansion for assignment statements that look like $PATH
1236 process substitution with named pipes if /dev/fd is not available
1237 the ${!param} indirect parameter expansion operator
Jari Aaltobb706242000-03-17 21:46:59 +00001238 the ${!param*} prefix expansion operator
Jari Aalto7117c2d2002-07-17 14:10:11 +00001239 the ${param:offset[:length]} parameter substring operator
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001240 the ${param/pat[/string]} parameter pattern substitution operator
Jari Aalto17345e52009-02-19 22:21:29 +00001241 variables: BASH, BASH_VERSION, BASH_VERSINFO, BASHPID, UID, EUID, SHLVL,
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001242 TIMEFORMAT, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE,
1243 HISTFILESIZE, HISTIGNORE, HISTCONTROL, PROMPT_COMMAND,
1244 IGNOREEOF, FIGNORE, INPUTRC, HOSTFILE, DIRSTACK,
1245 PIPESTATUS, HOSTNAME, OPTERR, SHELLOPTS, GLOBIGNORE,
Jari Aalto17345e52009-02-19 22:21:29 +00001246 GROUPS, FUNCNAME, histchars, auto_resume, PROMPT_DIRTRIM
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001247 prompt expansion with backslash escapes and command substitution
Jari Aalto17345e52009-02-19 22:21:29 +00001248 redirection: &> (stdout and stderr), <<<, [n]<&word-, [n]>&word-, >>&
Jari Aaltobb706242000-03-17 21:46:59 +00001249 more extensive and extensible editing and programmable completion
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001250 builtins: bind, builtin, command, declare, dirs, echo -e/-E, enable,
1251 exec -l/-c/-a, fc -s, export -n/-f/-p, hash, help, history,
1252 jobs -x/-r/-s, kill -s/-n/-l, local, logout, popd, pushd,
Chet Ramey00018032011-11-21 20:51:19 -05001253 read -e/-p/-a/-t/-n/-d/-s/-N, readonly -a/-n/-f/-p,
Jari Aaltobb706242000-03-17 21:46:59 +00001254 set -o braceexpand/-o histexpand/-o interactive-comments/
1255 -o notify/-o physical/-o posix/-o hashall/-o onecmd/
1256 -h/-B/-C/-b/-H/-P, set +o, suspend, trap -l, type,
Jari Aalto06285672006-10-10 14:15:34 +00001257 typeset -a/-F/-p, ulimit -i/-q/-u/-x, umask -S, alias -p,
Jari Aalto17345e52009-02-19 22:21:29 +00001258 shopt, disown, printf, complete, compgen, compopt, mapfile
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001259 `!' csh-style history expansion
Jari Aaltobc4cd231998-07-23 14:37:54 +00001260 POSIX.2-style globbing character classes
1261 POSIX.2-style globbing equivalence classes
1262 POSIX.2-style globbing collating symbols
1263 egrep-like extended pattern matching operators
1264 case-insensitive pattern matching and globbing
1265 `**' arithmetic operator to do exponentiation
Jari Aaltobb706242000-03-17 21:46:59 +00001266 redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr
Jari Aaltof73dda02001-11-13 17:56:06 +00001267 arrays of unlimited size
Jari Aalto7117c2d2002-07-17 14:10:11 +00001268 TMOUT is default timeout for `read' and `select'
Jari Aaltob80f6442004-07-27 13:29:18 +00001269 debugger support, including the `caller' builtin
1270 RETURN trap
1271 Timestamps in history entries
1272 {x..y} brace expansion
Jari Aalto95732b42005-12-07 14:08:12 +00001273 The `+=' assignment operator
Jari Aalto17345e52009-02-19 22:21:29 +00001274 autocd shell option and behavior
1275 command-not-found hook with command_not_found_handle shell function
1276 globstar shell option and `**' globbing behavior
1277 |& synonym for `2>&1 |'
1278 ;& and ;;& case action list terminators
1279 case-modifying word expansions and variable attributes
1280 associative arrays
1281 coprocesses using the `coproc' reserved word and variables
Chet Ramey00018032011-11-21 20:51:19 -05001282 shell assignment of a file descriptor used in a redirection to a variable
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001283
1284Things ksh88 has or uses that bash does not:
Jari Aaltof73dda02001-11-13 17:56:06 +00001285 tracked aliases (alias -t)
Jari Aaltobb706242000-03-17 21:46:59 +00001286 variables: ERRNO, FPATH, EDITOR, VISUAL
Jari Aalto17345e52009-02-19 22:21:29 +00001287 co-processes (bash uses different syntax)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001288 weirdly-scoped functions
1289 typeset +f to list all function names without definitions
1290 text of command history kept in a file, not memory
Jari Aaltob80f6442004-07-27 13:29:18 +00001291 builtins: alias -x, cd old new, newgrp, print,
Jari Aalto7117c2d2002-07-17 14:10:11 +00001292 read -p/-s/var?prompt, set -A/-o gmacs/
Jari Aaltob80f6442004-07-27 13:29:18 +00001293 -o bgnice/-o markdirs/-o trackall/-o viraw/-s,
Jari Aalto17345e52009-02-19 22:21:29 +00001294 typeset -H/-L/-R/-Z/-A/-ft/-fu/-fx/-t, whence
Jari Aaltof73dda02001-11-13 17:56:06 +00001295 using environment to pass attributes of exported variables
1296 arithmetic evaluation done on arguments to some builtins
1297 reads .profile from $PWD when invoked as login shell
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001298
1299Implementation differences:
1300 ksh runs last command of a pipeline in parent shell context
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001301 bash has brace expansion by default (ksh88 compile-time option)
1302 bash has fixed startup file for all interactive shells; ksh reads $ENV
1303 bash has exported functions
1304 bash command search finds functions before builtins
Jari Aaltof73dda02001-11-13 17:56:06 +00001305 bash waits for all commands in pipeline to exit before returning status
1306 emacs-mode editing has some slightly different key bindings
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001307
Jari Aaltob72432f1999-02-19 17:11:39 +00001308C3) Which new features in ksh-93 are not in bash, and which are?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001309
Chet Rameyac50fba2014-02-26 09:36:43 -05001310This list is current through ksh93v (10/08/2013)
Jari Aalto17345e52009-02-19 22:21:29 +00001311
Chet Rameyac50fba2014-02-26 09:36:43 -05001312New things in ksh-93 not in bash-4.3:
1313 floating point arithmetic, variables, and constants
1314 math library functions, including user-defined math functions
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001315 ${!name[sub]} name of subscript for associative array
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001316 `.' is allowed in variable names to create a hierarchical namespace
1317 more extensive compound assignment syntax
1318 discipline functions
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001319 KEYBD trap
Jari Aaltobb706242000-03-17 21:46:59 +00001320 variables: .sh.edchar, .sh.edmode, .sh.edcol, .sh.edtext, .sh.version,
Chet Rameyac50fba2014-02-26 09:36:43 -05001321 .sh.name, .sh.subscript, .sh.value, .sh.match, HISTEDIT,
1322 .sh.sig, .sh.stats, .sh.siginfo, .sh.pwdfd, .sh.op_astbin,
1323 .sh.pool
Jari Aaltof73dda02001-11-13 17:56:06 +00001324 backreferences in pattern matching (\N)
Jari Aalto17345e52009-02-19 22:21:29 +00001325 `&' operator in pattern lists for matching (match all instead of any)
1326 exit statuses between 0 and 255
1327 FPATH and PATH mixing
1328 lexical scoping for local variables in `ksh' functions
1329 no scoping for local variables in `POSIX' functions
1330 $'' \C[.collating-element.] escape sequence
1331 -C/-I invocation options
Chet Rameyac50fba2014-02-26 09:36:43 -05001332 print -f (bash uses printf) and rest of print builtin options
1333 printf %(type)q, %#q
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001334 `fc' has been renamed to `hist'
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001335 `.' can execute shell functions
Jari Aaltof73dda02001-11-13 17:56:06 +00001336 getopts -a
Chet Ramey495aee42011-11-22 19:11:26 -05001337 printf %B, %H, %P, %R, %Z modifiers, output base for %d, `=' flag
Chet Rameyac50fba2014-02-26 09:36:43 -05001338 read -n/-N differ/-v/-S
Jari Aalto17345e52009-02-19 22:21:29 +00001339 set -o showme/-o multiline (bash default)
Chet Rameyac50fba2014-02-26 09:36:43 -05001340 set -K
1341 kill -Q/-q/-L
1342 trap -a
Jari Aalto17345e52009-02-19 22:21:29 +00001343 `sleep' and `getconf' builtins (bash has loadable versions)
Chet Ramey00018032011-11-21 20:51:19 -05001344 [[ -R name ]] (checks whether or not name is a nameref)
Chet Rameyac50fba2014-02-26 09:36:43 -05001345 typeset -C/-S/-T/-X/-h/-s/-c/-M
Jari Aalto17345e52009-02-19 22:21:29 +00001346 experimental `type' definitions (a la typedef) using typeset
Jari Aalto17345e52009-02-19 22:21:29 +00001347 array expansions ${array[sub1..sub2]} and ${!array[sub1..sub2]}
1348 associative array assignments using `;' as element separator
1349 command substitution $(n<#) expands to current byte offset for fd N
1350 new '${ ' form of command substitution, executed in current shell
Chet Ramey00018032011-11-21 20:51:19 -05001351 new >;/<>;/<#pat/<##pat/<#/># redirections
Jari Aalto17345e52009-02-19 22:21:29 +00001352 brace expansion printf-like formats
Chet Rameyac50fba2014-02-26 09:36:43 -05001353 CHLD trap triggered by SIGSTOP and SIGCONT
1354 ~{fd} expansion, which replaces fd with the corresponding path name
1355 $"string" expanded when referenced rather than when first parsed
1356 job "pools", which allow a collection of jobs to be managed as a unit
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001357
Chet Rameyac50fba2014-02-26 09:36:43 -05001358New things in ksh-93 present in bash-4.3:
Jari Aalto17345e52009-02-19 22:21:29 +00001359 associative arrays
Jari Aalto7117c2d2002-07-17 14:10:11 +00001360 [n]<&word- and [n]>&word- redirections (combination dup and close)
Jari Aaltobb706242000-03-17 21:46:59 +00001361 for (( expr1; expr2; expr3 )) ; do list; done - arithmetic for command
1362 ?:, ++, --, `expr1 , expr2' arithmetic operators
1363 expansions: ${!param}, ${param:offset[:len]}, ${param/pat[/str]},
1364 ${!param*}
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001365 compound array assignment
Chet Ramey495aee42011-11-22 19:11:26 -05001366 negative subscripts for indexed array variables
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001367 the `!' reserved word
1368 loadable builtins -- but ksh uses `builtin' while bash uses `enable'
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001369 new $'...' and $"..." quoting
1370 FIGNORE (but bash uses GLOBIGNORE), HISTCMD
Jari Aalto17345e52009-02-19 22:21:29 +00001371 brace expansion and set -B
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001372 changes to kill builtin
Jari Aalto17345e52009-02-19 22:21:29 +00001373 `command', `builtin', `disown' builtins
1374 echo -e
1375 exec -c/-a
Chet Ramey495aee42011-11-22 19:11:26 -05001376 printf %T modifier
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001377 read -A (bash uses read -a)
Jari Aaltobb706242000-03-17 21:46:59 +00001378 read -t/-d
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001379 trap -p
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001380 `.' restores the positional parameters when it completes
Jari Aalto17345e52009-02-19 22:21:29 +00001381 set -o notify/-C
1382 set -o pipefail
1383 set -G (-o globstar) and **
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001384 POSIX.2 `test'
1385 umask -S
1386 unalias -a
1387 command and arithmetic substitution performed on PS1, PS4, and ENV
Jari Aalto17345e52009-02-19 22:21:29 +00001388 command name completion, TAB displaying possible completions
Jari Aaltod166f041997-06-05 14:59:13 +00001389 ENV processed only for interactive shells
Jari Aalto95732b42005-12-07 14:08:12 +00001390 The `+=' assignment operator
Jari Aalto17345e52009-02-19 22:21:29 +00001391 the `;&' case statement "fallthrough" pattern list terminator
1392 csh-style history expansion and set -H
1393 negative offsets in ${param:offset:length}
Chet Ramey00018032011-11-21 20:51:19 -05001394 redirection operators preceded with {varname} to store fd number in varname
1395 DEBUG can force skipping following command
Chet Ramey495aee42011-11-22 19:11:26 -05001396 [[ -v var ]] operator (checks whether or not var is set)
Chet Rameyac50fba2014-02-26 09:36:43 -05001397 typeset -n and `nameref' variables
1398 process substitutions work without /dev/fd
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001399
1400Section D: Why does bash do some things differently than other Unix shells?
1401
Jari Aaltob72432f1999-02-19 17:11:39 +00001402D1) Why does bash run a different version of `command' than
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001403 `which command' says it will?
1404
Jari Aaltob72432f1999-02-19 17:11:39 +00001405On many systems, `which' is actually a csh script that assumes
1406you're running csh. In tcsh, `which' and its cousin `where'
1407are builtins. On other Unix systems, `which' is a perl script
Jari Aalto31859422009-01-12 13:36:28 +00001408that uses the PATH environment variable. Many Linux distributions
1409use GNU `which', which is a C program that can understand shell
1410aliases.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001411
Jari Aaltob72432f1999-02-19 17:11:39 +00001412The csh script version reads the csh startup files from your
1413home directory and uses those to determine which `command' will
1414be invoked. Since bash doesn't use any of those startup files,
1415there's a good chance that your bash environment differs from
1416your csh environment. The bash `type' builtin does everything
1417`which' does, and will report correct results for the running
1418shell. If you're really wedded to the name `which', try adding
1419the following function definition to your .bashrc:
1420
1421 which()
1422 {
Jari Aaltobb706242000-03-17 21:46:59 +00001423 builtin type "$@"
Jari Aaltob72432f1999-02-19 17:11:39 +00001424 }
1425
1426If you're moving from tcsh and would like to bring `where' along
1427as well, use this function:
1428
1429 where()
1430 {
1431 builtin type -a "$@"
1432 }
1433
1434D2) Why doesn't bash treat brace expansions exactly like csh?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001435
1436The only difference between bash and csh brace expansion is that
1437bash requires a brace expression to contain at least one unquoted
1438comma if it is to be expanded. Any brace-surrounded word not
1439containing an unquoted comma is left unchanged by the brace
1440expansion code. This affords the greatest degree of sh
1441compatibility.
1442
1443Bash, ksh, zsh, and pd-ksh all implement brace expansion this way.
1444
Jari Aaltob72432f1999-02-19 17:11:39 +00001445D3) Why doesn't bash have csh variable modifiers?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001446
1447Posix has specified a more powerful, albeit somewhat more cryptic,
1448mechanism cribbed from ksh, and bash implements it.
1449
1450${parameter%word}
1451 Remove smallest suffix pattern. The WORD is expanded to produce
1452 a pattern. It then expands to the value of PARAMETER, with the
1453 smallest portion of the suffix matched by the pattern deleted.
1454
1455 x=file.c
1456 echo ${x%.c}.o
1457 -->file.o
1458
1459${parameter%%word}
1460
1461 Remove largest suffix pattern. The WORD is expanded to produce
1462 a pattern. It then expands to the value of PARAMETER, with the
1463 largest portion of the suffix matched by the pattern deleted.
1464
1465 x=posix/src/std
1466 echo ${x%%/*}
1467 -->posix
1468
1469${parameter#word}
1470 Remove smallest prefix pattern. The WORD is expanded to produce
1471 a pattern. It then expands to the value of PARAMETER, with the
1472 smallest portion of the prefix matched by the pattern deleted.
1473
1474 x=$HOME/src/cmd
1475 echo ${x#$HOME}
1476 -->/src/cmd
1477
1478${parameter##word}
1479 Remove largest prefix pattern. The WORD is expanded to produce
1480 a pattern. It then expands to the value of PARAMETER, with the
1481 largest portion of the prefix matched by the pattern deleted.
1482
1483 x=/one/two/three
1484 echo ${x##*/}
1485 -->three
1486
1487
1488Given
1489 a=/a/b/c/d
1490 b=b.xxx
1491
1492 csh bash result
1493 --- ---- ------
1494 $a:h ${a%/*} /a/b/c
1495 $a:t ${a##*/} d
1496 $b:r ${b%.*} b
1497 $b:e ${b##*.} xxx
1498
1499
Jari Aaltob72432f1999-02-19 17:11:39 +00001500D4) How can I make my csh aliases work when I convert to bash?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001501
1502Bash uses a different syntax to support aliases than csh does.
1503The details can be found in the documentation. We have provided
1504a shell script which does most of the work of conversion for you;
Jari Aalto28ef6c32001-04-06 19:14:31 +00001505this script can be found in ./examples/misc/aliasconv.sh. Here is
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001506how you use it:
1507
1508Start csh in the normal way for you. (e.g., `csh')
1509
Jari Aalto28ef6c32001-04-06 19:14:31 +00001510Pipe the output of `alias' through `aliasconv.sh', saving the
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001511results into `bash_aliases':
1512
Jari Aalto28ef6c32001-04-06 19:14:31 +00001513 alias | bash aliasconv.sh >bash_aliases
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001514
1515Edit `bash_aliases', carefully reading through any created
1516functions. You will need to change the names of some csh specific
1517variables to the bash equivalents. The script converts $cwd to
1518$PWD, $term to $TERM, $home to $HOME, $user to $USER, and $prompt
1519to $PS1. You may also have to add quotes to avoid unwanted
1520expansion.
1521
1522For example, the csh alias:
1523
1524 alias cd 'cd \!*; echo $cwd'
1525
1526is converted to the bash function:
1527
1528 cd () { command cd "$@"; echo $PWD ; }
1529
1530The only thing that needs to be done is to quote $PWD:
1531
1532 cd () { command cd "$@"; echo "$PWD" ; }
1533
1534Merge the edited file into your ~/.bashrc.
1535
1536There is an additional, more ambitious, script in
1537examples/misc/cshtobash that attempts to convert your entire csh
1538environment to its bash equivalent. This script can be run as
1539simply `cshtobash' to convert your normal interactive
1540environment, or as `cshtobash ~/.login' to convert your login
1541environment.
1542
Jari Aaltob72432f1999-02-19 17:11:39 +00001543D5) How can I pipe standard output and standard error from one command to
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001544 another, like csh does with `|&'?
1545
1546Use
1547 command 2>&1 | command2
1548
1549The key is to remember that piping is performed before redirection, so
1550file descriptor 1 points to the pipe when it is duplicated onto file
1551descriptor 2.
1552
Jari Aaltob72432f1999-02-19 17:11:39 +00001553D6) Now that I've converted from ksh to bash, are there equivalents to
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001554 ksh features like autoloaded functions and the `whence' command?
1555
Jari Aaltobb706242000-03-17 21:46:59 +00001556There are features in ksh-88 and ksh-93 that do not have direct bash
1557equivalents. Most, however, can be emulated with very little trouble.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001558
1559ksh-88 feature Bash equivalent
1560-------------- ---------------
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001561compiled-in aliases set up aliases in .bashrc; some ksh aliases are
1562 bash builtins (hash, history, type)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001563coprocesses named pipe pairs (one for read, one for write)
1564typeset +f declare -F
1565cd, print, whence function substitutes in examples/functions/kshenv
1566autoloaded functions examples/functions/autoload is the same as typeset -fu
1567read var?prompt read -p prompt var
1568
Jari Aaltobb706242000-03-17 21:46:59 +00001569ksh-93 feature Bash equivalent
1570-------------- ---------------
1571sleep, getconf Bash has loadable versions in examples/loadables
1572${.sh.version} $BASH_VERSION
1573print -f printf
Jari Aalto7117c2d2002-07-17 14:10:11 +00001574hist alias hist=fc
Jari Aaltobb706242000-03-17 21:46:59 +00001575$HISTEDIT $FCEDIT
1576
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001577Section E: How can I get bash to do certain things, and why does bash do
1578 things the way it does?
1579
Jari Aaltob72432f1999-02-19 17:11:39 +00001580E1) Why is the bash builtin `test' slightly different from /bin/test?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001581
1582The specific example used here is [ ! x -o x ], which is false.
1583
1584Bash's builtin `test' implements the Posix.2 spec, which can be
1585summarized as follows (the wording is due to David Korn):
1586
1587Here is the set of rules for processing test arguments.
1588
1589 0 Args: False
1590 1 Arg: True iff argument is not null.
1591 2 Args: If first arg is !, True iff second argument is null.
1592 If first argument is unary, then true if unary test is true
1593 Otherwise error.
1594 3 Args: If second argument is a binary operator, do binary test of $1 $3
1595 If first argument is !, negate two argument test of $2 $3
1596 If first argument is `(' and third argument is `)', do the
1597 one-argument test of the second argument.
1598 Otherwise error.
1599 4 Args: If first argument is !, negate three argument test of $2 $3 $4.
1600 Otherwise unspecified
1601 5 or more Args: unspecified. (Historical shells would use their
1602 current algorithm).
1603
1604The operators -a and -o are considered binary operators for the purpose
1605of the 3 Arg case.
1606
1607As you can see, the test becomes (not (x or x)), which is false.
1608
Jari Aaltob72432f1999-02-19 17:11:39 +00001609E2) Why does bash sometimes say `Broken pipe'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001610
1611If a sequence of commands appears in a pipeline, and one of the
1612reading commands finishes before the writer has finished, the
1613writer receives a SIGPIPE signal. Many other shells special-case
1614SIGPIPE as an exit status in the pipeline and do not report it.
1615For example, in:
1616
1617 ps -aux | head
1618
1619`head' can finish before `ps' writes all of its output, and ps
1620will try to write on a pipe without a reader. In that case, bash
1621will print `Broken pipe' to stderr when ps is killed by a
1622SIGPIPE.
1623
Jari Aalto06285672006-10-10 14:15:34 +00001624As of bash-3.1, bash does not report SIGPIPE errors by default. You
Jari Aalto95732b42005-12-07 14:08:12 +00001625can build a version of bash that will report such errors.
Jari Aaltob72432f1999-02-19 17:11:39 +00001626
Jari Aaltobb706242000-03-17 21:46:59 +00001627E3) When I have terminal escape sequences in my prompt, why does bash
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001628 wrap lines at the wrong column?
1629
1630Readline, the line editing library that bash uses, does not know
1631that the terminal escape sequences do not take up space on the
1632screen. The redisplay code assumes, unless told otherwise, that
1633each character in the prompt is a `printable' character that
1634takes up one character position on the screen.
1635
1636You can use the bash prompt expansion facility (see the PROMPTING
1637section in the manual page) to tell readline that sequences of
1638characters in the prompt strings take up no screen space.
1639
1640Use the \[ escape to begin a sequence of non-printing characters,
1641and the \] escape to signal the end of such a sequence.
1642
Jari Aaltobb706242000-03-17 21:46:59 +00001643E4) If I pipe the output of a command into `read variable', why doesn't
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001644 the output show up in $variable when the read command finishes?
1645
1646This has to do with the parent-child relationship between Unix
Jari Aalto28ef6c32001-04-06 19:14:31 +00001647processes. It affects all commands run in pipelines, not just
1648simple calls to `read'. For example, piping a command's output
1649into a `while' loop that repeatedly calls `read' will result in
1650the same behavior.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001651
Jari Aalto95732b42005-12-07 14:08:12 +00001652Each element of a pipeline, even a builtin or shell function,
1653runs in a separate process, a child of the shell running the
1654pipeline. A subprocess cannot affect its parent's environment.
1655When the `read' command sets the variable to the input, that
1656variable is set only in the subshell, not the parent shell. When
1657the subshell exits, the value of the variable is lost.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001658
1659Many pipelines that end with `read variable' can be converted
1660into command substitutions, which will capture the output of
1661a specified command. The output can then be assigned to a
1662variable:
1663
1664 grep ^gnu /usr/lib/news/active | wc -l | read ngroup
1665
1666can be converted into
1667
1668 ngroup=$(grep ^gnu /usr/lib/news/active | wc -l)
1669
1670This does not, unfortunately, work to split the text among
1671multiple variables, as read does when given multiple variable
1672arguments. If you need to do this, you can either use the
1673command substitution above to read the output into a variable
1674and chop up the variable using the bash pattern removal
1675expansion operators or use some variant of the following
1676approach.
1677
1678Say /usr/local/bin/ipaddr is the following shell script:
1679
1680#! /bin/sh
1681host `hostname` | awk '/address/ {print $NF}'
1682
1683Instead of using
1684
1685 /usr/local/bin/ipaddr | read A B C D
1686
1687to break the local machine's IP address into separate octets, use
1688
1689 OIFS="$IFS"
1690 IFS=.
1691 set -- $(/usr/local/bin/ipaddr)
1692 IFS="$OIFS"
1693 A="$1" B="$2" C="$3" D="$4"
1694
1695Beware, however, that this will change the shell's positional
1696parameters. If you need them, you should save them before doing
1697this.
1698
1699This is the general approach -- in most cases you will not need to
1700set $IFS to a different value.
1701
Jari Aaltof73dda02001-11-13 17:56:06 +00001702Some other user-supplied alternatives include:
1703
1704read A B C D << HERE
1705 $(IFS=.; echo $(/usr/local/bin/ipaddr))
1706HERE
1707
1708and, where process substitution is available,
1709
1710read A B C D < <(IFS=.; echo $(/usr/local/bin/ipaddr))
1711
Jari Aaltobb706242000-03-17 21:46:59 +00001712E5) I have a bunch of shell scripts that use backslash-escaped characters
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001713 in arguments to `echo'. Bash doesn't interpret these characters. Why
1714 not, and how can I make it understand them?
1715
1716This is the behavior of echo on most Unix System V machines.
1717
Jari Aaltobb706242000-03-17 21:46:59 +00001718The bash builtin `echo' is modeled after the 9th Edition
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001719Research Unix version of `echo'. It does not interpret
1720backslash-escaped characters in its argument strings by default;
1721it requires the use of the -e option to enable the
1722interpretation. The System V echo provides no way to disable the
1723special characters; the bash echo has a -E option to disable
1724them.
1725
1726There is a configuration option that will make bash behave like
1727the System V echo and interpret things like `\t' by default. Run
Jari Aaltof73dda02001-11-13 17:56:06 +00001728configure with the --enable-xpg-echo-default option to turn this
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001729on. Be aware that this will cause some of the tests run when you
1730type `make tests' to fail.
1731
Jari Aalto7117c2d2002-07-17 14:10:11 +00001732There is a shell option, `xpg_echo', settable with `shopt', that will
Jari Aaltobb706242000-03-17 21:46:59 +00001733change the behavior of echo at runtime. Enabling this option turns
1734on expansion of backslash-escape sequences.
1735
1736E6) Why doesn't a while or for loop get suspended when I type ^Z?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001737
1738This is a consequence of how job control works on Unix. The only
1739thing that can be suspended is the process group. This is a single
1740command or pipeline of commands that the shell forks and executes.
1741
1742When you run a while or for loop, the only thing that the shell forks
1743and executes are any commands in the while loop test and commands in
1744the loop bodies. These, therefore, are the only things that can be
1745suspended when you type ^Z.
1746
1747If you want to be able to stop the entire loop, you need to put it
1748within parentheses, which will force the loop into a subshell that
1749may be stopped (and subsequently restarted) as a single unit.
1750
Jari Aalto28ef6c32001-04-06 19:14:31 +00001751E7) What about empty for loops in Makefiles?
1752
1753It's fairly common to see constructs like this in automatically-generated
1754Makefiles:
1755
1756SUBDIRS = @SUBDIRS@
1757
1758 ...
1759
1760subdirs-clean:
1761 for d in ${SUBDIRS}; do \
1762 ( cd $$d && ${MAKE} ${MFLAGS} clean ) \
1763 done
1764
1765When SUBDIRS is empty, this results in a command like this being passed to
1766bash:
1767
1768 for d in ; do
1769 ( cd $d && ${MAKE} ${MFLAGS} clean )
1770 done
1771
Jari Aaltof73dda02001-11-13 17:56:06 +00001772In versions of bash before bash-2.05a, this was a syntax error. If the
1773reserved word `in' was present, a word must follow it before the semicolon
1774or newline. The language in the manual page referring to the list of words
1775being empty referred to the list after it is expanded. These versions of
1776bash required that there be at least one word following the `in' when the
1777construct was parsed.
Jari Aalto28ef6c32001-04-06 19:14:31 +00001778
1779The idiomatic Makefile solution is something like:
1780
1781SUBDIRS = @SUBDIRS@
1782
1783subdirs-clean:
1784 subdirs=$SUBDIRS ; for d in $$subdirs; do \
1785 ( cd $$d && ${MAKE} ${MFLAGS} clean ) \
1786 done
1787
Jari Aaltob80f6442004-07-27 13:29:18 +00001788The latest updated POSIX standard has changed this: the word list
1789is no longer required. Bash versions 2.05a and later accept the
1790new syntax.
Jari Aalto28ef6c32001-04-06 19:14:31 +00001791
1792E8) Why does the arithmetic evaluation code complain about `08'?
1793
1794The bash arithmetic evaluation code (used for `let', $(()), (()), and in
1795other places), interprets a leading `0' in numeric constants as denoting
1796an octal number, and a leading `0x' as denoting hexadecimal. This is
1797in accordance with the POSIX.2 spec, section 2.9.2.1, which states that
1798arithmetic constants should be handled as signed long integers as defined
1799by the ANSI/ISO C standard.
1800
1801The POSIX.2 interpretation committee has confirmed this:
1802
1803http://www.pasc.org/interps/unofficial/db/p1003.2/pasc-1003.2-173.html
1804
1805E9) Why does the pattern matching expression [A-Z]* match files beginning
1806 with every letter except `z'?
1807
Jari Aalto7117c2d2002-07-17 14:10:11 +00001808Bash-2.03, Bash-2.05 and later versions honor the current locale setting
1809when processing ranges within pattern matching bracket expressions ([A-Z]).
1810This is what POSIX.2 and SUSv3/XPG6 specify.
Jari Aalto28ef6c32001-04-06 19:14:31 +00001811
Jari Aaltof73dda02001-11-13 17:56:06 +00001812The behavior of the matcher in bash-2.05 and later versions depends on the
1813current LC_COLLATE setting. Setting this variable to `C' or `POSIX' will
1814result in the traditional behavior ([A-Z] matches all uppercase ASCII
1815characters). Many other locales, including the en_US locale (the default
1816on many US versions of Linux) collate the upper and lower case letters like
1817this:
Jari Aalto28ef6c32001-04-06 19:14:31 +00001818
1819 AaBb...Zz
1820
Jari Aalto7117c2d2002-07-17 14:10:11 +00001821which means that [A-Z] matches every letter except `z'. Others collate like
1822
1823 aAbBcC...zZ
1824
1825which means that [A-Z] matches every letter except `a'.
Jari Aalto28ef6c32001-04-06 19:14:31 +00001826
1827The portable way to specify upper case letters is [:upper:] instead of
1828A-Z; lower case may be specified as [:lower:] instead of a-z.
1829
1830Look at the manual pages for setlocale(3), strcoll(3), and, if it is
1831present, locale(1). If you have locale(1), you can use it to find
1832your current locale information even if you do not have any of the
1833LC_ variables set.
1834
1835My advice is to put
1836
1837 export LC_COLLATE=C
1838
1839into /etc/profile and inspect any shell scripts run from cron for
1840constructs like [A-Z]. This will prevent things like
1841
1842 rm [A-Z]*
1843
1844from removing every file in the current directory except those beginning
1845with `z' and still allow individual users to change the collation order.
1846Users may put the above command into their own profiles as well, of course.
1847
Jari Aalto7117c2d2002-07-17 14:10:11 +00001848E10) Why does `cd //' leave $PWD as `//'?
1849
1850POSIX.2, in its description of `cd', says that *three* or more leading
1851slashes may be replaced with a single slash when canonicalizing the
1852current working directory.
1853
1854This is, I presume, for historical compatibility. Certain versions of
1855Unix, and early network file systems, used paths of the form
1856//hostname/path to access `path' on server `hostname'.
1857
Jari Aaltob80f6442004-07-27 13:29:18 +00001858E11) If I resize my xterm while another program is running, why doesn't bash
1859 notice the change?
1860
1861This is another issue that deals with job control.
1862
1863The kernel maintains a notion of a current terminal process group. Members
1864of this process group (processes whose process group ID is equal to the
1865current terminal process group ID) receive terminal-generated signals like
1866SIGWINCH. (For more details, see the JOB CONTROL section of the bash
1867man page.)
1868
1869If a terminal is resized, the kernel sends SIGWINCH to each member of
1870the terminal's current process group (the `foreground' process group).
1871
1872When bash is running with job control enabled, each pipeline (which may be
1873a single command) is run in its own process group, different from bash's
1874process group. This foreground process group receives the SIGWINCH; bash
1875does not. Bash has no way of knowing that the terminal has been resized.
1876
1877There is a `checkwinsize' option, settable with the `shopt' builtin, that
1878will cause bash to check the window size and adjust its idea of the
1879terminal's dimensions each time a process stops or exits and returns control
1880of the terminal to bash. Enable it with `shopt -s checkwinsize'.
1881
1882E12) Why don't negative offsets in substring expansion work like I expect?
1883
1884When substring expansion of the form ${param:offset[:length} is used,
1885an `offset' that evaluates to a number less than zero counts back from
1886the end of the expanded value of $param.
1887
1888When a negative `offset' begins with a minus sign, however, unexpected things
1889can happen. Consider
1890
1891 a=12345678
1892 echo ${a:-4}
1893
1894intending to print the last four characters of $a. The problem is that
1895${param:-word} already has a well-defined meaning: expand to word if the
1896expanded value of param is unset or null, and $param otherwise.
1897
1898To use negative offsets that begin with a minus sign, separate the
1899minus sign and the colon with a space.
1900
Jari Aalto06285672006-10-10 14:15:34 +00001901E13) Why does filename completion misbehave if a colon appears in the filename?
1902
1903Filename completion (and word completion in general) may appear to behave
1904improperly if there is a colon in the word to be completed.
1905
1906The colon is special to readline's word completion code: it is one of the
1907characters that breaks words for the completer. Readline uses these characters
1908in sort of the same way that bash uses $IFS: they break or separate the words
1909the completion code hands to the application-specific or default word
1910completion functions. The original intent was to make it easy to edit
1911colon-separated lists (such as $PATH in bash) in various applications using
1912readline for input.
1913
1914This is complicated by the fact that some versions of the popular
1915`bash-completion' programmable completion package have problems with the
1916default completion behavior in the presence of colons.
1917
1918The current set of completion word break characters is available in bash as
1919the value of the COMP_WORDBREAKS variable. Removing `:' from that value is
1920enough to make the colon not special to completion:
1921
1922COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
1923
1924You can also quote the colon with a backslash to achieve the same result
1925temporarily.
1926
Jari Aalto31859422009-01-12 13:36:28 +00001927E14) Why does quoting the pattern argument to the regular expression matching
1928 conditional operator (=~) cause regexp matching to stop working?
1929
1930In versions of bash prior to bash-3.2, the effect of quoting the regular
1931expression argument to the [[ command's =~ operator was not specified.
1932The practical effect was that double-quoting the pattern argument required
1933backslashes to quote special pattern characters, which interfered with the
1934backslash processing performed by double-quoted word expansion and was
1935inconsistent with how the == shell pattern matching operator treated
1936quoted characters.
1937
1938In bash-3.2, the shell was changed to internally quote characters in single-
1939and double-quoted string arguments to the =~ operator, which suppresses the
1940special meaning of the characters special to regular expression processing
1941(`.', `[', `\', `(', `), `*', `+', `?', `{', `|', `^', and `$') and forces
1942them to be matched literally. This is consistent with how the `==' pattern
1943matching operator treats quoted portions of its pattern argument.
1944
1945Since the treatment of quoted string arguments was changed, several issues
1946have arisen, chief among them the problem of white space in pattern arguments
1947and the differing treatment of quoted strings between bash-3.1 and bash-3.2.
1948Both problems may be solved by using a shell variable to hold the pattern.
1949Since word splitting is not performed when expanding shell variables in all
1950operands of the [[ command, this allows users to quote patterns as they wish
1951when assigning the variable, then expand the values to a single string that
1952may contain whitespace. The first problem may be solved by using backslashes
1953or any other quoting mechanism to escape the white space in the patterns.
1954
Jari Aalto17345e52009-02-19 22:21:29 +00001955Bash-4.0 introduces the concept of a `compatibility level', controlled by
1956several options to the `shopt' builtin. If the `compat31' option is enabled,
1957bash reverts to the bash-3.1 behavior with respect to quoting the rhs of
1958the =~ operator.
1959
Chet Ramey00018032011-11-21 20:51:19 -05001960E15) Tell me more about the shell compatibility level.
1961
1962Bash-4.0 introduced the concept of a `shell compatibility level', specified
1963as a set of options to the shopt builtin (compat31, compat32, compat40 at
1964this writing). There is only one current compatibility level -- each
1965option is mutually exclusive. This list does not mention behavior that is
1966standard for a particular version (e.g., setting compat32 means that quoting
1967the rhs of the regexp matching operator quotes special regexp characters in
1968the word, which is default behavior in bash-3.2 and above).
1969
1970compat31 set
1971 - the < and > operators to the [[ command do not consider the current
1972 locale when comparing strings
1973 - quoting the rhs of the regexp matching operator (=~) has no
1974 special effect
1975
1976compat32 set
1977 - the < and > operators to the [[ command do not consider the current
1978 locale when comparing strings
1979
1980compat40 set
1981 - the < and > operators to the [[ command do not consider the current
1982 locale when comparing strings
1983 - interrupting a command list such as "a ; b ; c" causes the execution
Chet Ramey495aee42011-11-22 19:11:26 -05001984 of the entire list to be aborted (in versions before bash-4.0,
1985 interrupting one command in a list caused the next to be executed)
Chet Ramey00018032011-11-21 20:51:19 -05001986
Chet Rameyac50fba2014-02-26 09:36:43 -05001987compat41 set
1988 - interrupting a command list such as "a ; b ; c" causes the execution
1989 of the entire list to be aborted (in versions before bash-4.1,
1990 interrupting one command in a list caused the next to be executed)
1991 - when in posix mode, single quotes in the `word' portion of a
1992 double-quoted parameter expansion define a new quoting context and
1993 are treated specially
1994
1995compat42 set
1996 - the replacement string in double-quoted pattern substitution is not
1997 run through quote removal, as in previous versions
1998
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001999Section F: Things to watch out for on certain Unix versions
2000
Jari Aaltob72432f1999-02-19 17:11:39 +00002001F1) Why can't I use command line editing in my `cmdtool'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002002
2003The problem is `cmdtool' and bash fighting over the input. When
2004scrolling is enabled in a cmdtool window, cmdtool puts the tty in
2005`raw mode' to permit command-line editing using the mouse for
2006applications that cannot do it themselves. As a result, bash and
2007cmdtool each try to read keyboard input immediately, with neither
2008getting enough of it to be useful.
2009
2010This mode also causes cmdtool to not implement many of the
2011terminal functions and control sequences appearing in the
2012`sun-cmd' termcap entry. For a more complete explanation, see
2013that file examples/suncmd.termcap in the bash distribution.
2014
2015`xterm' is a better choice, and gets along with bash much more
2016smoothly.
2017
2018If you must use cmdtool, you can use the termcap description in
2019examples/suncmd.termcap. Set the TERMCAP variable to the terminal
2020description contained in that file, i.e.
2021
2022TERMCAP='Mu|sun-cmd:am:bs:km:pt:li#34:co#80:cl=^L:ce=\E[K:cd=\E[J:rs=\E[s:'
2023
2024Then export TERMCAP and start a new cmdtool window from that shell.
2025The bash command-line editing should behave better in the new
2026cmdtool. If this works, you can put the assignment to TERMCAP
2027in your bashrc file.
2028
Jari Aaltob72432f1999-02-19 17:11:39 +00002029F2) I built bash on Solaris 2. Why do globbing expansions and filename
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002030 completion chop off the first few characters of each filename?
2031
2032This is the consequence of building bash on SunOS 5 and linking
2033with the libraries in /usr/ucblib, but using the definitions
2034and structures from files in /usr/include.
2035
2036The actual conflict is between the dirent structure in
2037/usr/include/dirent.h and the struct returned by the version of
2038`readdir' in libucb.a (a 4.3-BSD style `struct direct').
2039
2040Make sure you've got /usr/ccs/bin ahead of /usr/ucb in your $PATH
2041when configuring and building bash. This will ensure that you
2042use /usr/ccs/bin/cc or acc instead of /usr/ucb/cc and that you
2043link with libc before libucb.
2044
2045If you have installed the Sun C compiler, you may also need to
2046put /usr/ccs/bin and /opt/SUNWspro/bin into your $PATH before
2047/usr/ucb.
2048
Jari Aaltob72432f1999-02-19 17:11:39 +00002049F3) Why does bash dump core after I interrupt username completion or
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002050 `~user' tilde expansion on a machine running NIS?
2051
2052This is a famous and long-standing bug in the SunOS YP (sorry, NIS)
2053client library, which is part of libc.
2054
2055The YP library code keeps static state -- a pointer into the data
2056returned from the server. When YP initializes itself (setpwent),
2057it looks at this pointer and calls free on it if it's non-null.
2058So far, so good.
2059
2060If one of the YP functions is interrupted during getpwent (the
2061exact function is interpretwithsave()), and returns NULL, the
2062pointer is freed without being reset to NULL, and the function
2063returns. The next time getpwent is called, it sees that this
2064pointer is non-null, calls free, and the bash free() blows up
2065because it's being asked to free freed memory.
2066
2067The traditional Unix mallocs allow memory to be freed multiple
2068times; that's probably why this has never been fixed. You can
2069run configure with the `--without-gnu-malloc' option to use
2070the C library malloc and avoid the problem.
2071
Jari Aaltob72432f1999-02-19 17:11:39 +00002072F4) I'm running SVR4.2. Why is the line erased every time I type `@'?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002073
2074The `@' character is the default `line kill' character in most
2075versions of System V, including SVR4.2. You can change this
2076character to whatever you want using `stty'. For example, to
2077change the line kill character to control-u, type
2078
2079 stty kill ^U
2080
2081where the `^' and `U' can be two separate characters.
2082
Jari Aaltob72432f1999-02-19 17:11:39 +00002083F5) Why does bash report syntax errors when my C News scripts use a
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002084 redirection before a subshell command?
2085
2086The actual command in question is something like
2087
2088 < file ( command )
2089
2090According to the grammar given in the POSIX.2 standard, this construct
2091is, in fact, a syntax error. Redirections may only precede `simple
2092commands'. A subshell construct such as the above is one of the shell's
2093`compound commands'. A redirection may only follow a compound command.
2094
Jari Aaltobb706242000-03-17 21:46:59 +00002095This affects the mechanical transformation of commands that use `cat'
2096to pipe a file into a command (a favorite Useless-Use-Of-Cat topic on
2097comp.unix.shell). While most commands of the form
2098
2099 cat file | command
2100
2101can be converted to `< file command', shell control structures such as
2102loops and subshells require `command < file'.
2103
Jari Aaltob80f6442004-07-27 13:29:18 +00002104The file CWRU/sh-redir-hack in the bash distribution is an
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002105(unofficial) patch to parse.y that will modify the grammar to
2106support this construct. It will not apply with `patch'; you must
2107modify parse.y by hand. Note that if you apply this, you must
2108recompile with -DREDIRECTION_HACK. This introduces a large
2109number of reduce/reduce conflicts into the shell grammar.
2110
Jari Aaltobb706242000-03-17 21:46:59 +00002111F6) Why can't I use vi-mode editing on Red Hat Linux 6.1?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002112
Jari Aaltobb706242000-03-17 21:46:59 +00002113The short answer is that Red Hat screwed up.
2114
2115The long answer is that they shipped an /etc/inputrc that only works
2116for emacs mode editing, and then screwed all the vi users by setting
2117INPUTRC to /etc/inputrc in /etc/profile.
2118
2119The short fix is to do one of the following: remove or rename
2120/etc/inputrc, set INPUTRC=~/.inputrc in ~/.bashrc (or .bash_profile,
2121but make sure you export it if you do), remove the assignment to
2122INPUTRC from /etc/profile, add
2123
2124 set keymap emacs
2125
2126to the beginning of /etc/inputrc, or bracket the key bindings in
2127/etc/inputrc with these lines
2128
2129 $if mode=emacs
2130 [...]
2131 $endif
2132
Jari Aalto7117c2d2002-07-17 14:10:11 +00002133F7) Why do bash-2.05a and bash-2.05b fail to compile `printf.def' on
2134 HP/UX 11.x?
2135
2136HP/UX's support for long double is imperfect at best.
2137
2138GCC will support it without problems, but the HP C library functions
2139like strtold(3) and printf(3) don't actually work with long doubles.
2140HP implemented a `long_double' type as a 4-element array of 32-bit
2141ints, and that is what the library functions use. The ANSI C
2142`long double' type is a 128-bit floating point scalar.
2143
2144The easiest fix, until HP fixes things up, is to edit the generated
2145config.h and #undef the HAVE_LONG_DOUBLE line. After doing that,
2146the compilation should complete successfully.
2147
Jari Aaltobb706242000-03-17 21:46:59 +00002148Section G: How can I get bash to do certain common things?
2149
2150G1) How can I get bash to read and display eight-bit characters?
2151
2152This is a process requiring several steps.
2153
2154First, you must ensure that the `physical' data path is a full eight
2155bits. For xterms, for example, the `vt100' resources `eightBitInput'
2156and `eightBitOutput' should be set to `true'.
2157
2158Once you have set up an eight-bit path, you must tell the kernel and
2159tty driver to leave the eighth bit of characters alone when processing
2160keyboard input. Use `stty' to do this:
2161
2162 stty cs8 -istrip -parenb
2163
2164For old BSD-style systems, you can use
2165
2166 stty pass8
2167
2168You may also need
2169
2170 stty even odd
2171
2172Finally, you need to tell readline that you will be inputting and
2173displaying eight-bit characters. You use readline variables to do
Chet Rameya0c0a002016-09-15 16:59:08 -04002174this. convert-meta says what to do if you read a character with its
2175eighth bit set. input-meta says whether to permit characters with the
2176eighth bit at all. output-meta determines how to display characters
2177with the eighth bit set: if on, they are output directly; if it is off,
2178such characters are displayed as a meta-prefixed escape sequence.
2179
2180These variables can be set in your .inputrc or using the bash
Jari Aaltobb706242000-03-17 21:46:59 +00002181`bind' builtin. Here's an example using `bind':
2182
2183 bash$ bind 'set convert-meta off'
Chet Rameya0c0a002016-09-15 16:59:08 -04002184 bash$ bind 'set input-meta on'
Jari Aaltobb706242000-03-17 21:46:59 +00002185 bash$ bind 'set output-meta on'
2186
2187The `set' commands between the single quotes may also be placed
2188in ~/.inputrc.
2189
Jari Aalto06285672006-10-10 14:15:34 +00002190The script examples/scripts.noah/meta.bash encapsulates the bind
2191commands in a shell function.
2192
Jari Aaltobb706242000-03-17 21:46:59 +00002193G2) How do I write a function `x' to replace builtin command `x', but
2194 still invoke the command from within the function?
2195
2196This is why the `command' and `builtin' builtins exist. The
2197`command' builtin executes the command supplied as its first
2198argument, skipping over any function defined with that name. The
2199`builtin' builtin executes the builtin command given as its first
2200argument directly.
2201
2202For example, to write a function to replace `cd' that writes the
2203hostname and current directory to an xterm title bar, use
2204something like the following:
2205
2206 cd()
2207 {
2208 builtin cd "$@" && xtitle "$HOST: $PWD"
2209 }
2210
2211This could also be written using `command' instead of `builtin';
2212the version above is marginally more efficient.
2213
2214G3) How can I find the value of a shell variable whose name is the value
2215 of another shell variable?
2216
2217Versions of Bash newer than Bash-2.0 support this directly. You can use
2218
2219 ${!var}
2220
2221For example, the following sequence of commands will echo `z':
2222
2223 var1=var2
2224 var2=z
2225 echo ${!var1}
2226
2227For sh compatibility, use the `eval' builtin. The important
2228thing to remember is that `eval' expands the arguments you give
2229it again, so you need to quote the parts of the arguments that
2230you want `eval' to act on.
2231
2232For example, this expression prints the value of the last positional
2233parameter:
2234
2235 eval echo \"\$\{$#\}\"
2236
2237The expansion of the quoted portions of this expression will be
2238deferred until `eval' runs, while the `$#' will be expanded
2239before `eval' is executed. In versions of bash later than bash-2.0,
2240
2241 echo ${!#}
2242
2243does the same thing.
2244
Jari Aaltof73dda02001-11-13 17:56:06 +00002245This is not the same thing as ksh93 `nameref' variables, though the syntax
Chet Rameyac50fba2014-02-26 09:36:43 -05002246is similar. Namerefs are available bash version 4.3, and work as in ksh93.
Jari Aaltof73dda02001-11-13 17:56:06 +00002247
Jari Aaltobb706242000-03-17 21:46:59 +00002248G4) How can I make the bash `time' reserved word print timing output that
2249 looks like the output from my system's /usr/bin/time?
2250
2251The bash command timing code looks for a variable `TIMEFORMAT' and
2252uses its value as a format string to decide how to display the
2253timing statistics.
2254
2255The value of TIMEFORMAT is a string with `%' escapes expanded in a
2256fashion similar in spirit to printf(3). The manual page explains
2257the meanings of the escape sequences in the format string.
2258
2259If TIMEFORMAT is not set, bash acts as if the following assignment had
2260been performed:
2261
2262 TIMEFORMAT=$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
2263
2264The POSIX.2 default time format (used by `time -p command') is
2265
2266 TIMEFORMAT=$'real %2R\nuser %2U\nsys %2S'
2267
2268The BSD /usr/bin/time format can be emulated with:
2269
2270 TIMEFORMAT=$'\t%1R real\t%1U user\t%1S sys'
2271
2272The System V /usr/bin/time format can be emulated with:
2273
2274 TIMEFORMAT=$'\nreal\t%1R\nuser\t%1U\nsys\t%1S'
2275
2276The ksh format can be emulated with:
2277
2278 TIMEFORMAT=$'\nreal\t%2lR\nuser\t%2lU\nsys\t%2lS'
2279
2280G5) How do I get the current directory into my prompt?
2281
2282Bash provides a number of backslash-escape sequences which are expanded
2283when the prompt string (PS1 or PS2) is displayed. The full list is in
2284the manual page.
2285
2286The \w expansion gives the full pathname of the current directory, with
2287a tilde (`~') substituted for the current value of $HOME. The \W
2288expansion gives the basename of the current directory. To put the full
2289pathname of the current directory into the path without any tilde
2290subsitution, use $PWD. Here are some examples:
2291
2292 PS1='\w$ ' # current directory with tilde
2293 PS1='\W$ ' # basename of current directory
2294 PS1='$PWD$ ' # full pathname of current directory
2295
2296The single quotes are important in the final example to prevent $PWD from
2297being expanded when the assignment to PS1 is performed.
2298
2299G6) How can I rename "*.foo" to "*.bar"?
2300
2301Use the pattern removal functionality described in D3. The following `for'
2302loop will do the trick:
2303
2304 for f in *.foo; do
2305 mv $f ${f%foo}bar
2306 done
2307
2308G7) How can I translate a filename from uppercase to lowercase?
2309
2310The script examples/functions/lowercase, originally written by John DuBois,
2311will do the trick. The converse is left as an exercise.
2312
2313G8) How can I write a filename expansion (globbing) pattern that will match
2314 all files in the current directory except "." and ".."?
2315
2316You must have set the `extglob' shell option using `shopt -s extglob' to use
2317this:
2318
2319 echo .!(.|) *
2320
2321A solution that works without extended globbing is given in the Unix Shell
Jari Aalto31859422009-01-12 13:36:28 +00002322FAQ, posted periodically to comp.unix.shell. It's a variant of
2323
2324 echo .[!.]* ..?* *
2325
2326(The ..?* catches files with names of three or more characters beginning
2327with `..')
Jari Aaltobb706242000-03-17 21:46:59 +00002328
2329Section H: Where do I go from here?
2330
2331H1) How do I report bugs in bash, and where should I look for fixes and
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002332 advice?
2333
2334Use the `bashbug' script to report bugs. It is built and
2335installed at the same time as bash. It provides a standard
2336template for reporting a problem and automatically includes
2337information about your configuration and build environment.
2338
Jari Aaltob72432f1999-02-19 17:11:39 +00002339`bashbug' sends its reports to bug-bash@gnu.org, which
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002340is a large mailing list gatewayed to the usenet newsgroup gnu.bash.bug.
2341
2342Bug fixes, answers to questions, and announcements of new releases
2343are all posted to gnu.bash.bug. Discussions concerning bash features
2344and problems also take place there.
2345
2346To reach the bash maintainers directly, send mail to
Jari Aaltob72432f1999-02-19 17:11:39 +00002347bash-maintainers@gnu.org.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002348
Jari Aaltobb706242000-03-17 21:46:59 +00002349H2) What kind of bash documentation is there?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002350
2351First, look in the doc directory in the bash distribution. It should
2352contain at least the following files:
2353
2354bash.1 an extensive, thorough Unix-style manual page
2355builtins.1 a manual page covering just bash builtin commands
Jari Aaltob72432f1999-02-19 17:11:39 +00002356bashref.texi a reference manual in GNU tex`info format
2357bashref.info an info version of the reference manual
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002358FAQ this file
2359article.ms text of an article written for The Linux Journal
2360readline.3 a man page describing readline
2361
Jari Aaltob72432f1999-02-19 17:11:39 +00002362Postscript, HTML, and ASCII files created from the above source are
2363available in the documentation distribution.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002364
2365There is additional documentation available for anonymous FTP from host
Jari Aaltocce855b1998-04-17 19:52:44 +00002366ftp.cwru.edu in the `pub/bash' directory.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002367
2368Cameron Newham and Bill Rosenblatt have written a book on bash, published
2369by O'Reilly and Associates. The book is based on Bill Rosenblatt's Korn
Jari Aaltod166f041997-06-05 14:59:13 +00002370Shell book. The title is ``Learning the Bash Shell'', and the ISBN number
Jari Aalto06285672006-10-10 14:15:34 +00002371of the third edition, published in March, 2005, is 0-596-00965-8. Look for
2372it in fine bookstores near you. This edition of the book has been updated
2373to cover bash-3.0.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002374
Jari Aaltob80f6442004-07-27 13:29:18 +00002375The GNU Bash Reference Manual has been published as a printed book by
Jari Aalto31859422009-01-12 13:36:28 +00002376Network Theory Ltd (Paperback, ISBN: 0-9541617-7-7, Nov. 2006). It covers
2377bash-3.2 and is available from most online bookstores (see
Jari Aaltob80f6442004-07-27 13:29:18 +00002378http://www.network-theory.co.uk/bash/manual/ for details). The publisher
2379will donate $1 to the Free Software Foundation for each copy sold.
2380
Jari Aalto06285672006-10-10 14:15:34 +00002381Arnold Robbins and Nelson Beebe have written ``Classic Shell Scripting'',
2382published by O'Reilly. The first edition, with ISBN number 0-596-00595-4,
2383was published in May, 2005.
2384
2385Chris F. A. Johnson, a frequent contributor to comp.unix.shell and
2386gnu.bash.bug, has written ``Shell Scripting Recipes: A Problem-Solution
2387Approach,'' a new book on shell scripting, concentrating on features of
2388the POSIX standard helpful to shell script writers. The first edition from
2389Apress, with ISBN number 1-59059-471-1, was published in May, 2005.
2390
Jari Aaltobb706242000-03-17 21:46:59 +00002391H3) What's coming in future versions?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002392
Jari Aaltof73dda02001-11-13 17:56:06 +00002393These are features I hope to include in a future version of bash.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002394
Jari Aalto17345e52009-02-19 22:21:29 +00002395Rocky Bernstein's bash debugger (support is included with bash-4.0)
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002396
Jari Aaltobb706242000-03-17 21:46:59 +00002397H4) What's on the bash `wish list' for future versions?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002398
2399These are features that may or may not appear in a future version of bash.
2400
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002401breaking some of the shell functionality into embeddable libraries
Jari Aaltobb706242000-03-17 21:46:59 +00002402a module system like zsh's, using dynamic loading like builtins
Jari Aaltobb706242000-03-17 21:46:59 +00002403a bash programmer's guide with a chapter on creating loadable builtins
2404a better loadable interface to perl with access to the shell builtins and
2405 variables (contributions gratefully accepted)
Jari Aaltof73dda02001-11-13 17:56:06 +00002406ksh93-like `xx.yy' variables (including some of the .sh.* variables) and
2407 associated disipline functions
2408Some of the new ksh93 pattern matching operators, like backreferencing
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002409
Jari Aaltobb706242000-03-17 21:46:59 +00002410H5) When will the next release appear?
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002411
Chet Rameyac50fba2014-02-26 09:36:43 -05002412The next version will appear sometime in 2015. Never make predictions.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002413
Chet Rameyac50fba2014-02-26 09:36:43 -05002414This document is Copyright 1995-2014 by Chester Ramey.
Jari Aaltoccc6cda1996-12-23 17:02:34 +00002415
2416Permission is hereby granted, without written agreement and
2417without license or royalty fees, to use, copy, and distribute
2418this document for any purpose, provided that the above copyright
2419notice appears in all copies of this document and that the
2420contents of this document remain unaltered.