home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / unix-faq / shell / bash next >
Encoding:
Internet Message Format  |  2004-04-27  |  70.5 KB

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