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