2. Bash, version 3

On July 27, 2004, Chet Ramey released version 3 of Bash. This update fixed quite a number of bugs and added new features.

Some of the more important added features:

Caution

The update to version 3 of Bash breaks a few scripts that worked under earlier versions. Test critical legacy scripts to make sure they still work!

As it happens, a couple of the scripts in the Advanced Bash Scripting Guide had to be fixed up (see Example 9.4, “Timed read, for instance).

2.1. Bash, version 3.1

The version 3.1 update of Bash introduces a number of bugfixes and a few minor changes.

  • The += operator is now permitted in in places where previously only the = assignment operator was recognized.

    a=1
    echo $a        # 1
    
    a+=5           # Won't work under versions of Bash earlier than 3.1.
    echo $a        # 15
    
    a+=Hello
    echo $a        # 15Hello

    Here, += functions as a string concatenation operator. Note that its behavior in this particular context is different than within a let construct.

    a=1
    echo $a        # 1
    
    let a+=5       # Integer arithmetic, rather than string concatenation.
    echo $a        # 6
    
    let a+=Hello   # Doesn't "add" anything to a.
    echo $a        # 6

    Jeffrey Haemer points out that this concatenation operator can be quite useful. In this instance, we append a directory to the $PATH.

    bash$ echo $PATH
    /usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/games
    
    
    bash$ PATH+=:/opt/bin
    
    bash$ echo $PATH
    /usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin/:/usr/games:/opt/bin
          

2.2. Bash, version 3.2

This is pretty much a bugfix update.