From J.J.Troup@dcsun7.comp.brad.ac.uk Tue Jul 9 11:54:33 1996 Flags: 10 Return-Path: J.J.Troup@dcsun7.comp.brad.ac.uk Received: from babar.INS.CWRU.Edu (root@babar.INS.CWRU.Edu [129.22.8.213]) by odin.INS.CWRU.Edu with ESMTP (8.6.12+cwru/CWRU-2.2-ins) id LAA05781; Tue, 9 Jul 1996 11:54:32 -0400 (from J.J.Troup@dcsun7.comp.brad.ac.uk for ) Received: from dcsun7.comp.brad.ac.uk (dcsun7.comp.brad.ac.uk [143.53.28.202]) by babar.INS.CWRU.Edu with ESMTP (8.6.13+cwru/CWRU-2.4) id LAA12069; Tue, 9 Jul 1996 11:54:03 -0400 (from J.J.Troup@dcsun7.comp.brad.ac.uk for ) Received: from dcsun4.comp.brad.ac.uk (jjtroup@dcsun4.comp.brad.ac.uk [143.53.28.201]) by dcsun7.comp.brad.ac.uk (8.7.5/8.7.3) with ESMTP id QAA29654 for ; Tue, 9 Jul 1996 16:54:06 +0100 (BST) Received: (from jjtroup@localhost) by dcsun4.comp.brad.ac.uk (8.7.5/8.7.3) id QAA22933; Tue, 9 Jul 1996 16:53:52 +0100 (BST) Date: Tue, 9 Jul 1996 16:53:52 +0100 (BST) Message-Id: <199607091553.QAA22933@dcsun4.comp.brad.ac.uk> From: JJ TROUP To: chet@po.CWRU.Edu Subject: Re: Bash FAQ in HTML? In-Reply-To: <9607091537.AA05105.SM@odin.INS.CWRU.Edu> References: <199607091532.QAA22766@dcsun4.comp.brad.ac.uk> <9607091537.AA05105.SM@odin.INS.CWRU.Edu> Chet Ramey writes: > > Is there a HTML version of the Bash FAQ? If not do you want one? I > > have converted it to HTML and if there isn't already a HTML-ised FAQ, > > I wondered if you wanted one? > > Sure, send it along. Thanks. Here it is. It is (with the exception of the
tags at the beginning) clean HTML 2.0. Although there were a couple of places which really warranted tables, I opted for

#

##

###

###

###

###

###

###

####

####

####

####

###

####

####

####

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

###

####

###

###

     instead as
    there is still no text based browser that I know of which fully
    supports tables.
      If you like it, I would be happy to update as and when the FAQ
    is. If there are bits you don't like please do tell me.  If you don't
    like it at all, that's cool too... :)

    Regards

    Cajun

    -------------------------------------------------------------
                  http://www.brad.ac.uk/~jjtroup/
    -------------------------------------------------------------

    --++Begin Include++--

    Bash FAQ

    This is the Bash FAQ, version 1.5, for Bash version 1.14.6.

    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.

    Contents:

    What is it?

    What's the latest version?

    Where can I get it?

    What's the `Posix 1003.2 standard'?

    On what machines will bash run?

    How does bash differ from sh, the Bourne shell?

    How does bash differ from the Korn shell, version ksh88?

    What is the bash `posix mode'?

    How can I build bash with gcc?

    Why does bash run a different version of `command' than `which command' says it will?

    How can I make my csh aliases work when I convert to bash?

    Now that I've converted from ksh to bash, are there equivalents to ksh features like autoloaded functions and the `whence' command?

    Why is the bash builtin `test' slightly different from /bin/test?

    Why does bash sometimes say `Broken pipe'?

    How can I get bash to read and display eight-bit characters?

    Why can't I use command line editing in my `cmdtool'?

    How do I write a function `x' to replace builtin command `x', but still invoke the command from within the function?

    When I have terminal escape sequences in my prompt, why does bash wrap lines at the wrong column?

    I built bash on Solaris 2.  Why do globbing expansions and filename completion chop off the first few characters of each filename?

    Why doesn't bash treat brace expansions exactly like csh?

    Why does bash dump core after I interrupt username completion or `~user' tilde expansion on a machine running NIS?

    I'm running SVR4.2.  Why is the line erased every time I type `@'?

    How can I find the value of a shell variable whose name is the value of another shell variable?

    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?

    I just changed my shell to bash, and now I can't FTP into my machine. Why not?

    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?

    Why doesn't bash have csh variable modifiers?

    Why does bash report syntax errors when my C News scripts use a redirection before a subshell command?

    How can I pipe standard output and standard error from one command to another, like csh does with `|&'?

    How do I report bugs in bash, and where should I look for fixes and advice?

    What kind of bash documentation is there?

    What's coming in future versions?

    What's on the bash `wish list'?

    When will the next release appear?

    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 1.14.6, first made available on December 19, 1995.

    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 slc2.ins.cwru.edu, the maintainer's machine.  The following URLs tell how to get version 1.14.6:

    ftp://prep.ai.mit.edu/pub/gnu/bash-1.14.6.tar.gz
    ftp://slc2.ins.cwru.edu/pub/dist/bash-1.14.6.tar.gz

    4)  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.

    5)  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 `make'.  The build process will attempt to discover the version of UNIX you have and tailor itself accordingly, using a combination of saved definitions in the file `machines.h' and a file `sysdefs.h' created by inspecting the environment for various things.

    More information appears in the file `INSTALL' in the distribution.

    6)  How does bash differ from sh, the Bourne shell?

    This is a non-comprehensive list of features that differentiate bash
    from the SVR4 shell.  The bash manual page explains these completely.

    Things bash has that sh does not:

    long invocation options
    `!' reserved word to invert pipeline return value
    the select compound command
    the $(...) form of command substitution
    the ${#param} parameter value length operator
    expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
    variables: BASH, BASH_VERSION, UID, EUID, REPLY, PPID, PWD, OLDPWD, SHLVL, RANDOM, SECONDS, LINENO, HISTCMD, HOSTTYPE, OSTYPE, ENV, MAIL_WARNING, PS3, PS4, HISTSIZE, HISTFILE, HISTFILESIZE, PROMPT_COMMAND, FCEDIT, FIGNORE, IGNOREEOF, INPUTRC, HISTCONTROL, command_oriented_history, allow_null_glob_expansion, glob_dot_filenames, histchars, nolinks, auto_resume, HOSTFILE, noclobber, TMOUT, no_exit_on_failed_exec, cdable_vars, notify, OPTERR
    redirections: <>, &>, >|
    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 -, exec -, echo -e/-E, export -n/-f/-p/name=value, pwd -P, read -r, readonly -f, trap -l, ulimit -n/-p/-u, set -b/-m/-o option/-p/-l/-d/-C/-H/-P, unset -f/-v, umask -S, type -all/-path/-type, suspend -f, kill -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 and `let' builtin
    process substitution
    aliases and alias/unalias builtins
    local variables in functions and `local' builtin
    readline and command-line editing
    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
    exported functions
    filename generation when using output redirection (command >a*)

    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'
    ulimit attempts to set both soft & hard limits if -S/-H not given

    New things in the SVR4.2 sh:

    internationalization: $LANG, $LC_CTYPE, $LC_MESSAGES, setlocale, etc.
    $TIMEOUT (like bash $TMOUT)
    new builtins: mldmode, priv
    `read' builtin has -r
    kill -s is present

    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
    sh does not allow MAILCHECK to be unset (?)
    sh does not allow traps on SIGALRM or SIGCHLD

    7)  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
    variables: BASH, BASH_VERSION, UID, EUID, SHLVL, HISTCMD, HOSTTYPE, OSTYPE, MAIL_WARNING, HISTFILESIZE, OPTERR, PROMPT_COMMAND, IGNOREEOF, FIGNORE, INPUTRC, HISTCONTROL, notify, command_oriented_history, glob_dot_filenames, allow_null_glob_expansion, histchars, nolinks, HOSTFILE, noclobber, auto_resume, no_exit_on_failed_exec, cdable_vars
    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 -, fc -s, export -n/-f/-p, hash, help, history, jobs -x, kill -s, local, logout, popd, pushd, readonly -n/-f/-p, set -o braceexpand/-o histexpand/-o interactive-comments/-o notify/-o physical/-o posix/-l/-d/-C/-b/-H/-P, suspend, trap -l, type, ulimit -u, umask -S
    $[...] synonym for $((...))
    `!' csh-style history expansion

    Things ksh88 has or uses that bash does not:

    new version of test: [[...]]
    ((...)) equivalent to let "..."
    time keyword to let pipelines be timed
    tracked aliases
    $(<file)
    one-dimensional arrays and appropriate expansions
    variables: ERRNO, FPATH, COLUMNS, LINES, EDITOR, VISUAL
    extended pattern matching with egrep-style pattern lists
    co-processes (|&, >&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 keyword/-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
    ksh ulimit sets hard and soft limits by default
    bash has brace expansion by default
    bash has fixed startup file for all interactive shells; ksh reads $ENV
    bash has exported functions
    bash command search finds functions before builtins

    8)  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.

    9) How can I build bash with gcc?

    Type

    	make CC=gcc CPPNAME='$(CC) -E'

    10) 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.

    11) 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/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 csh specific variables (like $cwd) to the bash equivalents (like $PWD).  You will also need to remove recursive references to commands which are defined as functions.  For example, the csh alias:

    	alias cd 'cd \!*;echo $cwd'

    is converted to the bash function:

    	cd ()
    	{
    		cd $*;
    		echo $cwd
    	}

    This function contains a self-pointing reference to `cd', which should be changed to use the `builtin' version.  It also uses the csh variable `$cwd' which has an equivalent in bash.  You should also change $* to "$@" to correctly process directory names with embedded spaces.  Precede the recursive reference with the word `builtin', change the name of the variable to the one bash uses, and quote it to avoid any unwanted expansion:

    	cd () { builtin cd "$@"; echo "$PWD"; }

    Merge the edited file into your ~/.bashrc.

    12) 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
    compiled-in aliases	set up aliases in .bashrc; some ksh aliases are
    			bash builtins (hash, history, type)
    $(<file)		$(cat file)
    arrays			no good subsitute yet
    ((...))			let "..."
    time			use external command; GNU time is particularly useful
    			use time bash -c '...' for complicated constructs
    extended patterns	no good substitute
    coprocesses		named pipe pairs (one for read, one for write)
    typeset +f		declare -f |
    			     sed -n 's:^declare -[a-z]* \([^ ]*\).*$:\1:p'
    cd, print, whence	function subsitutes in examples/functions/kshenv
    autoloaded functions	examples/functions/autoload is the same as typeset -fu
    read var?prompt		[ -t 0 ] && echo -n prompt >&2; read var

    13) Why is the bash builtin `test' slightly different from /bin/test?

    The specific example used here is [ ! x -o x ], which is false.

    Bash's builtin `test' implements the Posix.2 spec, which can be summarized as follows (the wording is due to David Korn):

    Here is the set of rules for processing test arguments.

        0 Args: False
        1 Arg:  True iff argument is not null.
        2 Args: If first arg is !, True iff second argument is null.
    	    If first argument is unary, then true if unary test is true
    	    Otherwise error.
        3 Args: If second argument is a binary operator, do binary test of $1 $3
    	    If first argument is !, negate two argument test of $2 $3
    	    Otherwise error.
        4 Args: If first argument is !, negate three argument test of $2 $3 $4.
    	    Otherwise unspecified
        5 or more Args: unspecified.  (Historical shells would use their
        current algorithm).

    The operators -a and -o are considered binary operators for the purpose of the 3 Arg case.

    As you can see, the test becomes (not (x or x)), which is false.

    14) Why does bash sometimes say `Broken pipe'?

    If a sequence of commands appears in a pipeline, and one of the reading commands finishes before the writer has finished, the writer receives a SIGPIPE signal.  Many other shells special-case SIGPIPE as an exit status in the pipeline and do not report it.  For example, in:

          ps -aux | head

    `head' can finish before `ps' writes all of its output, and ps will try to write on a pipe without a reader.  In that case, bash will print `Broken pipe' to stderr when ps is killed by a SIGPIPE.

    15) How can I get bash to read and display eight-bit characters?

    This is a process requiring several steps.

    First, you must ensure that the `physical' data path is a full eight bits.  For xterms, for example, the `vt100' resources `eightBitInput' and `eightBitOutput' should be set to `true'.

    Once you have set up an eight-bit path, you must tell the kernel and tty driver to leave the eigth bit of characters alone when processing keyboard input.  Use `stty' to do this:

    	stty cs8 -istrip -parenb

    For old BSD-style systems, you can use

            stty pass8

    You may also need

    	stty even odd

    Finally, you need to tell readline that you will be inputting and displaying eight-bit characters.  You use readline variables to do this.  These variables can be set in your .inputrc or using the bash `bind' builtin.  Here's an example using `bind':

    	bash$ bind 'set convert-meta off'
    	bash$ bind 'set meta-flag on'
    	bash$ bind 'set output-meta on'

    The `set' commands between the single quotes may also be placed in ~/.inputrc.

    16) Why can't I use command line editing in my `cmdtool'?

    The problem is `cmdtool' and bash fighting over the input.  When scrolling is enabled in a cmdtool window, cmdtool puts the tty in `raw mode' to permit command-line editing using the mouse for applications that cannot do it themselves.  As a result, bash and cmdtool each try to read keyboard input immediately, with neither getting enough of it to be useful.

    This mode also causes cmdtool to not implement many of the terminal functions and control sequences appearing in the `sun-cmd' termcap entry.  For a more complete explanation, see that file examples/suncmd.termcap in the bash distribution.

    `xterm' is a better choice, and gets along with bash much more smoothly.

    If you must use cmdtool, you can use the termcap description in examples/suncmd.termcap.  Set the TERMCAP variable to the terminal description contained in that file, i.e.

    TERMCAP='Mu|sun-cmd:am:bs:km:pt:li#34:co#80:cl=^L:ce=\E[K:cd=\E[J:rs=\E[s:'

    Then export TERMCAP and start a new cmdtool window from that shell. The bash command-line editing should behave better in the new cmdtool.  If this works, you can put the assignment to TERMCAP in your bashrc file.

    17) How do I write a function `x' to replace builtin command `x', but still invoke the command from within the function?

    This is what the `command' and `builtin' builtins are for.  The `command' builtin executes the command supplied as its first argument, skipping over any function defined with that name.  The `builtin' builtin executes the builtin command given as its first argument directly.

    For example, to write a function to replace `cd' that writes the hostname and current directory to an xterm title bar, use something like the following:

    	cd()
    	{
    		builtin cd "$@" && xtitle "$HOST: $PWD"
    	}

    This could also be written using `command' instead of `builtin'; the version above is marginally more efficient.

    18) When I have terminal escape sequences in my prompt, why does bash wrap lines at the wrong column?

    Bash does not know that the terminal escape sequences do not take up space on the screen.  The redisplay code assumes, unless told otherwise, that each character in the prompt is a `printable' character that takes up one character position on the screen.

    You can use the bash prompt expansion facility (see the PROMPTING section in the manual page) to tell readline that sequences of characters in the prompt strings take up no screen space.

    Use the \[ escape to begin a sequence of non-printing characters, and the \] escape to signal the end of such a sequence.

    19) I built bash on Solaris 2.  Why do globbing expansions and filename completion chop off the first few characters of each filename?

    This is the consequence of building bash on SunOS 5 and linking with the libraries in /usr/ucblib, but using the definitions and structures from files in /usr/include.

    The actual conflict is between the dirent structure in /usr/include/dirent.h and the struct returned by the version of `readdir' in libucb.a (a 4.3-BSD style `struct direct').

    Make sure you've got /usr/ccs/bin ahead of /usr/ucb in your $PATH when building bash.  This will ensure that you use /usr/ccs/bin/cc or acc instead of /usr/ucb/cc and that you link with libc before libucb.

    If you have installed the Sun C compiler, you may also need to put /usr/ccs/bin and /opt/SUNWspro/bin into your $PATH before /usr/ucb.

    20) 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.

    21) Why does bash dump core after I interrupt username completion or `~user' tilde expansion on a machine running NIS?

    This is a famous and long-standing bug in the SunOS YP (sorry, NIS) client library, which is part of libc.

    The YP library code keeps static state -- a pointer into the data returned from the server.  When YP initializes itself (setpwent), it looks at this pointer and calls free on it if it's non-null.  So far, so good.

    If one of the YP functions is interrupted during getpwent (the exact function is interpretwithsave()), and returns NULL, the pointer is freed without being reset to NULL, and the function returns.  The next time getpwent is called, it sees that this pointer is non-null, calls free, and the bash free() blows up because it's being asked to free freed memory.

    The traditional Unix mallocs allow memory to be freed multiple times; that's probably why this has never been fixed.  You can probably stop it by adding an #undef USE_GNU_MALLOC to the appropriate machine description in machines.h.

    22) I'm running SVR4.2.  Why is the line erased every time I type `@'?

    The `@' character is the default `line kill' character in most versions of System V, including SVR4.2.  You can change this character to whatever you want using `stty'.  For example, to change the line kill character to control-u, type

    	stty kill ^U

    where the `^' and `U' can be two separate characters.

    23) How can I find the value of a shell variable whose name is the value of another shell variable?

    Use the `eval' builtin.  The important thing to remember is that `eval' expands the arguments you give it again, so you need to quote the parts of the arguments that you want `eval' to act on.

    For example, this expression prints the value of the last positional parameter:

    	eval echo \"\$\{$#\}\"

    The expansion of the quoted portions of this expression will be deferred until `eval' runs, while the `$#' will be expanded before `eval' is executed.

    24) 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?

    This has to do with the parent-child relationship between Unix processes.

    Each element of a pipeline runs in a separate process, a child of the shell running the pipeline.  A subprocess cannot affect its parent's environment.  When the `read' command sets the variable to the input, that variable is set only in the subshell, not the parent shell.  When the subshell exits, the value of the variable is lost.

    Many pipelines that end with `read variable' can be converted into command substitutions, which will capture the output of a specified command.  The output can then be assigned to a variable:

    	grep ^gnu /usr/lib/news/active | wc -l | read ngroup

    can be converted into

    	ngroup=$(grep ^gnu /usr/lib/news/active | wc -l)

    This does not, unfortunately, work to split the text among multiple variables, as read does when given multiple variable arguments.  If you need to do this, you can either use the command substitution above to read the output into a variable and chop up the variable using the bash pattern removal expansion operators or use some variant of the following approach.

    Say /usr/local/bin/ipaddr is the following shell script:

    #! /bin/sh
    host `hostname` | awk '/address/ {print $NF}'

    Instead of using

    	/usr/local/bin/ipaddr | read A B C D

    to break the local machine's IP address into separate octets, use

    	OIFS="$IFS"
    	IFS=.
    	set -- $(/usr/local/bin/ipaddr)
    	IFS="$OIFS"
    	A="$1" B="$2" C="$3" D="$4"

    Beware, however, that this will change the shell's positional parameters.  If you need them, you should save them before doing this.

    This is the general approach -- in most cases you will not need to set $IFS to a different value.

    25) I just changed my 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. Many versions of ftpd use this file to prohibit `special' users such as `uucp' and `news' from using FTP.

    26) 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?

    This is the behavior of echo on most Unix System V machines.

    The bash builtin `echo' is modelled after the 9th Edition Research Unix version of `echo'.  It does not interpret backslash-escaped characters in its argument strings by default; it requires the use of the -e option to enable the interpretation.  The System V echo provides no way to disable the special characters; the bash echo has a -E option to disable them.

    There is a compile-time option that will make bash behave like the System V echo and interpret things like \t by default.  Change config.h so that DEFAULT_ECHO_TO_USG is defined, remove builtins/libbuiltins.a and builtins/echo.o, and rebuild.

    27) Why doesn't bash have csh variable modifiers?

    Posix has specified a more powerful, albeit somewhat more confusing, 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

    28) Why does bash report syntax errors when my C News scripts use a redirection before a subshell command?

    The actual command in question is something like

    	< file ( command )

    According to the grammar given in the Posix.2 standard, this construct is, in fact, a syntax error.  Redirections may only precede `simple commands'.  A subshell construct such as the above is one of the shell's `compound commands'.  A redirection may only follow a compound command.

    The file CWRU/sh-redir-hack in the 1.14.6 distribution is an (unofficial) patch to parse.y that will modify the grammar to support this construct. It will not apply with `patch'; you must modify parse.y by hand. Note that if you apply this, you must recompile with -DREDIRECTION_HACK. This introduces a large number of reduce/reduce conflicts into the shell grammar.

    29) 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.

    30) How do I report bugs in bash, and where should I look for fixes and advice?

    Use the `bashbug' script to report bugs.  It is built and installed at the same time as bash.  It provides a standard template for reporting a problem and automatically includes information about your configuration and build environment.

    `bashbug' sends its reports to bug-bash@prep.ai.mit.edu, which is a large mailing list gatewayed to the usenet newsgroup gnu.bash.bug.

    Bug fixes, answers to questions, and announcements of new releases are all posted to gnu.bash.bug.  Discussions concerning bash features and problems also take place there.

    To reach the bash maintainers directly, send mail to bash-maintainers@prep.ai.mit.edu.

    31) What kind of bash documentation is there?

    First, look in the documentation directory in the bash distribution. It should contain the following files:

    bash.1 - an extensive, thorough Unix-style manual page
    builtins.1 - a manual page covering just bash builtin commands
    features.texi - a Gnu-style info file overview
    FAQ	- this file
    article.ms - text of an article written for The Linux Journal
    readline.3 - a man page describing readline

    Postscript files created from the above source are also present in the distribution.

    There is additional documentation available for anonymous FTP from host slc2.ins.cwru.edu in the `pub/bash' directory.

    Cameron Newham has written a book on bash, published by O'Reilly and Associates.  The title is ``Learning the Bash Shell''.  The ISBN number s 1-56592-147-X.  Look for it in fine bookstores near you.

    32) What's coming in future versions?

    There will be no new features in future releases of version 1.14.

    The next major release, bash-2.0, will contain extensive changes and new features.  Here's a short list:

    one-dimensional arrays with a new compound assignment statement, appropriate expansion constructs and modifications to some of the builtins (read, declare, etc.) to use them
    new expansions to do ANSI-C string expansion, locale-specific string translation, substring extraction, pattern replacement, and indirect variable expansion
    new builtins: `disown' and `shopt'
    new variables: HISTIGNORE, SHELLOPTS, PIPESTATUS, DIRSTACK, GLOBIGNORE
    special handling of many unused or redundant variables removed (e.g., $notify, $glob_dot_filenames, $no_exit_on_failed_exec)
    dynamic loading of new builtin commands; many loadable examples provided
    new prompt expansions: \e, \n, \H, \T, \@, \v, \V
    history and aliases available in shell scripts
    new readline variables: enable-keypad, mark-directories, input-meta, visible-stats
    new readline commands to manipulate the mark and operate on the region
    new readline emacs mode commands and bindings for ksh-88 compatibility
    updated and extended builtins
    new DEBUG trap
    expanded (and now documented) restricted shell mode
    the `time' reserved word to time pipelines, shell builtins, and shell functions

    implementation stuff:

    autoconf-based configuration
    nearly all of the bugs reported since version 1.14 have been fixed
    most builtins converted to use builtin `getopt' for consistency
    most builtins use -p option to display output in a reusable form (for consistency)
    grammar tighter and smaller (66 reduce-reduce conflicts gone)
    lots of code now smaller and faster
    test suite greatly expanded

    33) What's on the bash `wish list' for future versions?

    Programmable completion a la zsh
    menu completion a la tcsh
    the ksh egrep-style extended pattern matching operators
    associative arrays (not really all that hard)
    breaking some of the shell functionality into embeddable libraries
    better internationalization using GNU `gettext'
    an option to use external files for the long `help' text
    a bash debugger

    Much of this will not be in bash-2.0.

    34) When will the next release appear?

    Version 1.14.6 will probably be the last release for version 1.14.

    The next version will appear sometime in 1996.  Never make predictions.

    This document is Copyright 1995, 1996 by Chester Ramey.

    Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, and distribute this document for any purpose, provided that the above copyright notice appears in all copies of this document and that the contents of this document remain unaltered.

    --

    ``The lyf so short, the craft so long to lerne.'' - Chaucer

    Chet Ramey, Case Western Reserve University - Internet: chet@po.CWRU.Edu

    --++ End Include ++--