This is the Bash FAQ, version 2.11, for Bash version 2.02. This document contains a set of frequently-asked questions concerning Bash, the GNU Bourne-Again Shell. Bash is a freely-available command interpreter with advanced features for both interactive use and shell programming. Another good source of basic information about shells is the collection of FAQ articles periodically posted to comp.unix.shell. Questions and comments concerning this document should be sent to chet@po.cwru.edu. This document is available for anonymous FTP with the URL ftp://ftp.cwru.edu/pub/bash/FAQ ---------- Contents: Section A: The Basics 1) What is it? 2) What's the latest version? 3) Where can I get it? 4) On what machines will bash run? 5) Will bash run on operating systems other than Unix? 6) How can I build bash with gcc? 7) How can I make bash my login shell? 8) I just changed my login shell to bash, and now I can't FTP into my machine. Why not? 9) What's the `POSIX 1003.2 standard'? 10) What is the bash `posix mode'? Section B: The latest version 11) What's new in version 2.02? 12) Are there any user-visible incompatibilities between bash-2.02 and bash-1.14.7? Section C: Differences from other Unix shells 13) How does bash differ from sh, the Bourne shell? 14) How does bash differ from the Korn shell, version ksh88? 15) Which new features in ksh-93 are not in bash, and which are? Section D: Why does bash do some things differently than other Unix shells? 16) Why does bash run a different version of `command' than `which command' says it will? 17) Why doesn't bash treat brace expansions exactly like csh? 18) Why doesn't bash have csh variable modifiers? 19) How can I make my csh aliases work when I convert to bash? 20) How can I pipe standard output and standard error from one command to another, like csh does with `|&'? 21) Now that I've converted from ksh to bash, are there equivalents to ksh features like autoloaded functions and the `whence' command? Section E: How can I get bash to do certain things, and why does bash do things the way it does? 22) Why is the bash builtin `test' slightly different from /bin/test? 23) Why does bash sometimes say `Broken pipe'? 24) How can I get bash to read and display eight-bit characters? 25) How do I write a function `x' to replace builtin command `x', but still invoke the command from within the function? 26) When I have terminal escape sequences in my prompt, why does bash wrap lines at the wrong column? 27) How can I find the value of a shell variable whose name is the value of another shell variable? 28) If I pipe the output of a command into `read variable', why doesn't the output show up in $variable when the read command finishes? 29) I have a bunch of shell scripts that use backslash-escaped characters in arguments to `echo'. Bash doesn't interpret these characters. Why not, and how can I make it understand them? 30) Why doesn't a while or for loop get suspended when I type ^Z? 31) How can I make the bash `time' reserved word print timing output that looks like the output from my system's /usr/bin/time? Section F: Things to watch out for on certain Unix versions 32) Why can't I use command line editing in my `cmdtool'? 33) I built bash on Solaris 2. Why do globbing expansions and filename completion chop off the first few characters of each filename? 34) Why does bash dump core after I interrupt username completion or `~user' tilde expansion on a machine running NIS? 35) I'm running SVR4.2. Why is the line erased every time I type `@'? 36) Why does bash report syntax errors when my C News scripts use a redirection before a subshell command? Section G: Where do I go from here? 37) How do I report bugs in bash, and where should I look for fixes and advice? 38) What kind of bash documentation is there? 39) What's coming in future versions? 40) What's on the bash `wish list'? 41) When will the next release appear? ---------- Section A: The Basics 1) What is it? Bash is a Unix command interpreter (shell). It is an implementation of the Posix 1003.2 shell standard, and resembles the Korn and System V shells. Bash contains a number of enhancements over those shells, both for interactive use and shell programming. Features geared toward interactive use include command line editing, command history, job control, aliases, and prompt expansion. Programming features include additional variable expansions, shell arithmetic, and a number of variables and options to control shell behavior. Bash was originally written by Brian Fox of the Free Software Foundation. The current developer and maintainer is Chet Ramey of Case Western Reserve University. 2) What's the latest version? The latest version is 2.02, first made available on Monday, 20 April, 1998. 3) Where can I get it? Bash is the GNU project's shell, and so is available from the master GNU archive site, prep.ai.mit.edu, and its mirrors. The latest version is also available for FTP from ftp.cwru.edu. The following URLs tell how to get version 2.02: ftp://prep.ai.mit.edu/pub/gnu/bash-2.02.tar.gz ftp://ftp.cwru.edu/pub/bash/bash-2.02.tar.gz Formatted versions of the documentation are available with the URLs: ftp://prep.ai.mit.edu/pub/gnu/bash-doc-2.02.tar.gz ftp://ftp.cwru.edu/pub/bash/bash-doc-2.02.tar.gz 4) On what machines will bash run? Bash has been ported to nearly every version of UNIX. All you should have to do to build it on a machine for which a port exists is to type `configure' and then `make'. The build process will attempt to discover the version of UNIX you have and tailor itself accordingly, using a script created by GNU autoconf. More information appears in the file `INSTALL' in the distribution. 5) Will bash run on operating systems other than Unix? Configuration specifics for Unix-like systems such as QNX and LynxOS are included in the distribution. Previous versions of bash have been ported to Minix, but I don't believe anyone has built bash-2.x on Minix yet. Bash has been ported to versions of Windows implementing the Win32 programming interface. This includes Windows 95 and Windows NT. The port was done by Cygnus Solutions as part of their GNU-Win32 project. For more information about the project, look at the URL http://www.cygnus.com/misc/gnu-win32 Cygnus has ported bash-1.14.7, and their port is part of the current gnu-win32 release. Cygnus has also done a port of bash-2.01 to the GNU-Win32 environment, and it should be available as part of their next release. Bash-2.02 should require no local Cygnus changes to build and run under GNU-WIN32. The Cygnus port works only on Intel machines. There is a port of bash (I don't know which version) to the alpha/NT environment available from ftp://ftp.gnustep.org//pub/win32/bash-alpha-nt-1.01.tar.gz Softway Systems has ported bash-2.01.1 to their OpenNT system, a Unix subsystem for NT that replaces the Microsoft POSIX subsystem. Check out http://www.opennt.com for more information. D. J. Delorie has ported bash-1.14.7 to run under MS-DOS, as part of the DJGPP project. For more information on the project, see http://www.delorie.com/djgpp/ I picked up a binary of bash-1.14.7 that is purported to work with the DJGPP V2 environment from ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147b.zip The corresponding source is ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsh1147s.zip Ports of bash-1.12 and bash-2.0 are available for OS/2 from ftp://hobbes.nmsu.edu/pub/os2/util/shell/bash_112.zip ftp://hobbes.nmsu.edu/pub/os2/util/shell/bash-2.0(253).zip I haven't looked at either, but the second appears to be a binary-only distribution. Beware. 6) How can I build bash with gcc? Bash configures to use gcc by default if it is available. Read the file INSTALL in the distribution for more information. 7) How can I make bash my login shell? Some machines let you use `chsh' to change your login shell. Other systems use `passwd -s' or `passwd -e'. If one of these works for you, that's all you need. Note that many systems require the full pathname to a shell to appear in /etc/shells before you can make it your login shell. For this, you may need the assistance of your friendly local system administrator. If you cannot do this, you can still use bash as your login shell, but you need to perform some tricks. The basic idea is to add a command to your login shell's startup file to replace your login shell with bash. For example, if your login shell is csh or tcsh, and you have installed bash in /usr/gnu/bin/bash, add the following line to ~/.login: if ( -f /usr/gnu/bin/bash ) exec /usr/gnu/bin/bash --login (the `--login' tells bash that it is a login shell). It's not a good idea to put this command into ~/.cshrc, because every csh you run without the `-f' option, even ones started to run csh scripts, reads that file. If you must put the command in ~/.cshrc, use something like if ( $?prompt ) exec /usr/gnu/bin/bash --login to ensure that bash is exec'd only when the csh is interactive. If your login shell is sh or ksh, you have to do two things. First, create an empty file in your home directory named `.bash_profile'. The existence of this file will prevent the exec'd bash from trying to read ~/.profile, and re-execing itself over and over again. ~/.bash_profile is the first file bash tries to read initialization commands from when it is invoked as a login shell. Next, add a line similar to the above to ~/.profile: [ -f /usr/gnu/bin/bash ] && exec /usr/gnu/bin/bash --login This will cause login shells to replace themselves with bash running as a login shell. Once you have this working, you can copy your initialization code from ~/.profile to ~/.bash_profile. 8) I just changed my login shell to bash, and now I can't FTP into my machine. Why not? You must add the full pathname to bash to the file /etc/shells. As noted in the answer to the previous question, many systems require this before you can make bash your login shell. Most versions of ftpd use this file to prohibit `special' users such as `uucp' and `news' from using FTP. 9) What's the `POSIX 1003.2 standard'? POSIX is a name originally coined by Richard Stallman for a family of open system standards based on UNIX. There are a number of aspects of UNIX under consideration for standardization, from the basic system services at the system call and C library level to applications and tools to system administration and management. Each area of standardization is assigned to a working group in the 1003 series. The POSIX Shell and Utilities standard has been developed by IEEE Working Group 1003.2 (POSIX.2). It concentrates on the command interpreter interface and utility programs commonly executed from the command line or by other programs. An initial version of the standard has been approved and published by the IEEE, and work is currently underway to update it. Bash is concerned with the aspects of the shell's behavior defined by POSIX.2. The shell command language has of course been standardized, including the basic flow control and program execution constructs, I/O redirection and pipelining, argument handling, variable expansion, and quoting. The `special' builtins, which must be implemented as part of the shell to provide the desired functionality, are specified as being part of the shell; examples of these are `eval' and `export'. Other utilities appear in the sections of POSIX.2 not devoted to the shell which are commonly (and in some cases must be) implemented as builtin commands, such as `read' and `test'. POSIX.2 also specifies aspects of the shell's interactive behavior as part of the UPE, including job control and command line editing. Only vi-style line editing commands have been standardized; emacs editing commands were left out due to objections. 10) What is the bash `posix mode'? Although bash is an implementation of the POSIX.2 shell specification, there are areas where the bash default behavior differs from that spec. The bash `posix mode' changes the bash behavior in these areas so that it obeys the spec more closely. Posix mode is entered by starting bash with the --posix option or executing `set -o posix' after bash is running. The specific aspects of bash which change when posix mode is active are listed in the file CWRU/POSIX.NOTES in the bash distribution. They are also listed in a section in the Bash Reference Manual. Section B: The latest version 11) What's new in version 2.02? Bash-2.02 has a number of new features. Here's a short list: a new version of malloc (based on the old GNU malloc code in previous bash versions) that is more page-oriented, more conservative with memory usage, does not `orphan' large blocks when they are freed, is usable on 64-bit machines, and has allocation checking turned on unconditionally POSIX.2-style globbing character classes ([:alpha:], [:alnum:], etc.) POSIX.2-style globbing equivalence classes POSIX.2-style globbing collating symbols the ksh [[...]] extended conditional command the ksh egrep-style extended pattern matching operators a new `printf' builtin the ksh-like $(, &>, >| prompt string special char translation and variable expansion auto-export of modified values of variables in initial environment command search finds functions before builtins bash return builtin will exit a file sourced with `.' builtins: cd -/-L/-P, exec -l/-c/-a, echo -e/-E, hash -p. export -n/-f/-p/name=value, pwd -L/-P, read -e/-p/-a, readonly -a/-f/name=value, trap -l, set +o, set -b/-m/-o option/-h/-p/-B/-C/-H/-P, unset -f/-v, ulimit -m/-p/-u, type -a/-p/-t, suspend -f, kill -n, test -o optname/s1 == s2/s1 < s2/s1 > s2/-nt/-ot/-ef/-O/-G/-S bash reads ~/.bashrc for interactive shells, $ENV for non-interactive bash restricted shell mode is more extensive bash allows functions and variables with the same name brace expansion tilde expansion arithmetic expansion with $((...)) and `let' builtin process substitution aliases and alias/unalias builtins local variables in functions and `local' builtin readline and command-line editing command history and history/fc builtins csh-like history expansion other new bash builtins: bind, command, builtin, declare/typeset, dirs, enable, fc, help, history, logout, popd, pushd, disown, shopt exported functions filename generation when using output redirection (command >a*) variable assignments preceding commands affect only that command, even for builtins and functions posix mode Things sh has that bash does not: uses variable SHACCT to do shell accounting includes `stop' builtin (bash can use alias stop='kill -s STOP') `newgrp' builtin turns on job control if called as `jsh' $TIMEOUT (like bash $TMOUT) `^' is a synonym for `|' new SVR4.2 sh builtins: mldmode, priv Implementation differences: redirection to/from compound commands causes sh to create a subshell bash does not allow unbalanced quotes; sh silently inserts them at EOF bash does not mess with signal 11 sh sets (euid, egid) to (uid, gid) if -p not supplied and uid < 100 bash splits only the results of expansions on IFS, using POSIX.2 field splitting rules; sh splits all words on IFS sh does not allow MAILCHECK to be unset (?) sh does not allow traps on SIGALRM or SIGCHLD bash allows multiple option arguments when invoked (e.g. -x -v); sh allows only a single option argument (`sh -x -v' attempts to open a file named `-v', and, on SunOS 4.1.4, dumps core. On Solaris 2, sh goes into an infinite loop.) sh exits a script if any builtin fails; bash exits only if one of the POSIX.2 `special' builtins fails 14) How does bash differ from the Korn shell, version ksh88? Things bash has or uses that ksh88 does not: long invocation options `!' reserved word posix mode and posix conformance command hashing tilde expansion for assignment statements that look like $PATH process substitution with named pipes if /dev/fd is not available the ${!param} indirect parameter expansion operator the ${param:length[:offset]} parameter substring operator the ${param/pat[/string]} parameter pattern substitution operator variables: BASH, BASH_VERSION, BASH_VERSINFO, UID, EUID, SHLVL, TIMEFORMAT, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE, HISTFILESIZE, HISTIGNORE, HISTCONTROL, PROMPT_COMMAND, IGNOREEOF, FIGNORE, INPUTRC, HOSTFILE, DIRSTACK, PIPESTATUS, HOSTNAME, OPTERR, SHELLOPTS, GLOBIGNORE, histchars, auto_resume prompt expansion with backslash escapes and command substitution redirection: &> (stdout and stderr) more extensive and extensible editing and completion builtins: bind, builtin, command, declare, dirs, echo -e/-E, enable, exec -l/-c/-a, fc -s, export -n/-f/-p, hash, help, history, jobs -x/-r/-s, kill -s/-n/-l, local, logout, popd, pushd, read -e/-p/-a, readonly -a/-n/-f/-p, set -o braceexpand/ -o histexpand/-o interactive-comments/-o notify/-o physical/ -o posix/-o hashall/-o onecmd/-h/-B/-C/-b/-H/-P, set +o, suspend, trap -l, type, typeset -a/-F/-p, ulimit -u, umask -S, alias -p, shopt, disown `!' csh-style history expansion Things ksh88 has or uses that bash does not: new version of test: [[...]] tracked aliases $(&p, <&p) weirdly-scoped functions typeset +f to list all function names without definitions text of command history kept in a file, not memory builtins: alias -x, cd old new, fc -e -, newgrp, print, read -p/-s/-u/var?prompt, set -A/-o gmacs/ -o bgnice/-o markdirs/-o nolog/-o trackall/-o viraw/-s, typeset -H/-L/-R/-A/-ft/-fu/-fx/-l/-u/-t, whence Implementation differences: ksh runs last command of a pipeline in parent shell context bash has brace expansion by default (ksh88 compile-time option) bash has fixed startup file for all interactive shells; ksh reads $ENV bash has exported functions bash command search finds functions before builtins 15) Which new features in ksh-93 are not in bash, and which are? New things in ksh-93 not in bash-2.02: associative arrays floating point arithmetic ++, --, comma arithmetic operators math library functions ${!name[sub]} name of subscript for associative array ${!prefix*} and {!prefix@} variable name prefix expansions `.' is allowed in variable names to create a hierarchical namespace more extensive compound assignment syntax discipline functions `sleep' and `getconf' builtins (bash has loadable versions) typeset -n and `nameref' variables KEYBD trap variables: .sh.edchar, .sh.edmode, .sh.edcol, .sh.edtext, HISTEDIT, .sh.version, .sh.name, .sh.subscript, .sh.value backreferences in pattern matching print -f (bash has a loadable version) `fc' has been renamed to `hist' read -t/-d `.' can execute shell functions New things in ksh-93 present in bash-2.02: ?: arithmetic operator expansions: ${!param}, ${param:offset[:len]}, ${param/pat[/str]} compound array assignment the `!' reserved word loadable builtins -- but ksh uses `builtin' while bash uses `enable' `command', `builtin', `disown' builtins new $'...' and $"..." quoting FIGNORE (but bash uses GLOBIGNORE), HISTCMD set -o notify/-C changes to kill builtin read -A (bash uses read -a) trap -p exec -c/-a `.' restores the positional parameters when it completes POSIX.2 `test' umask -S unalias -a command and arithmetic substitution performed on PS1, PS4, and ENV command name completion ENV processed only for interactive shells Section D: Why does bash do some things differently than other Unix shells? 16) Why does bash run a different version of `command' than `which command' says it will? `which' is actually a csh script that assumes you're running csh. It reads the csh startup files from your home directory and uses those to determine which `command' will be invoked. Since bash doesn't use any of those startup files, there's a good chance that your bash environment differs from your csh environment. 17) Why doesn't bash treat brace expansions exactly like csh? The only difference between bash and csh brace expansion is that bash requires a brace expression to contain at least one unquoted comma if it is to be expanded. Any brace-surrounded word not containing an unquoted comma is left unchanged by the brace expansion code. This affords the greatest degree of sh compatibility. Bash, ksh, zsh, and pd-ksh all implement brace expansion this way. 18) Why doesn't bash have csh variable modifiers? Posix has specified a more powerful, albeit somewhat more cryptic, mechanism cribbed from ksh, and bash implements it. ${parameter%word} Remove smallest suffix pattern. The WORD is expanded to produce a pattern. It then expands to the value of PARAMETER, with the smallest portion of the suffix matched by the pattern deleted. x=file.c echo ${x%.c}.o -->file.o ${parameter%%word} Remove largest suffix pattern. The WORD is expanded to produce a pattern. It then expands to the value of PARAMETER, with the largest portion of the suffix matched by the pattern deleted. x=posix/src/std echo ${x%%/*} -->posix ${parameter#word} Remove smallest prefix pattern. The WORD is expanded to produce a pattern. It then expands to the value of PARAMETER, with the smallest portion of the prefix matched by the pattern deleted. x=$HOME/src/cmd echo ${x#$HOME} -->/src/cmd ${parameter##word} Remove largest prefix pattern. The WORD is expanded to produce a pattern. It then expands to the value of PARAMETER, with the largest portion of the prefix matched by the pattern deleted. x=/one/two/three echo ${x##*/} -->three Given a=/a/b/c/d b=b.xxx csh bash result --- ---- ------ $a:h ${a%/*} /a/b/c $a:t ${a##*/} d $b:r ${b%.*} b $b:e ${b##*.} xxx 19) How can I make my csh aliases work when I convert to bash? Bash uses a different syntax to support aliases than csh does. The details can be found in the documentation. We have provided a shell script which does most of the work of conversion for you; this script can be found in ./examples/misc/alias-conv.sh. Here is how you use it: Start csh in the normal way for you. (e.g., `csh') Pipe the output of `alias' through `alias-conv.sh', saving the results into `bash_aliases': alias | alias-conv.sh >bash_aliases Edit `bash_aliases', carefully reading through any created functions. You will need to change the names of some csh specific variables to the bash equivalents. The script converts $cwd to $PWD, $term to $TERM, $home to $HOME, $user to $USER, and $prompt to $PS1. You may also have to add quotes to avoid unwanted expansion. For example, the csh alias: alias cd 'cd \!*; echo $cwd' is converted to the bash function: cd () { command cd "$@"; echo $PWD ; } The only thing that needs to be done is to quote $PWD: cd () { command cd "$@"; echo "$PWD" ; } Merge the edited file into your ~/.bashrc. There is an additional, more ambitious, script in examples/misc/cshtobash that attempts to convert your entire csh environment to its bash equivalent. This script can be run as simply `cshtobash' to convert your normal interactive environment, or as `cshtobash ~/.login' to convert your login environment. 20) How can I pipe standard output and standard error from one command to another, like csh does with `|&'? Use command 2>&1 | command2 The key is to remember that piping is performed before redirection, so file descriptor 1 points to the pipe when it is duplicated onto file descriptor 2. 21) Now that I've converted from ksh to bash, are there equivalents to ksh features like autoloaded functions and the `whence' command? There are features in ksh-88 that do not have direct bash equivalents. Most, however, can be emulated with very little trouble. ksh-88 feature Bash equivalent -------------- --------------- [[...]] can usually use [...]; minor differences (no pattern matching, for one) compiled-in aliases set up aliases in .bashrc; some ksh aliases are bash builtins (hash, history, type) $(