LWN.net Logo

Bash 4.0 brings new capabilities

By Forrest Cook
February 25, 2009

On February 23, 2009 version 4.0 of the BASH shell, a.k.a. the Bourne-Again SHell, was announced (see the initial LWN article for reader comments). For Linux users, at least those users who use the command line, BASH and its associated built-in commands could easily make up the most frequently run suite of Linux utilities. The BASH version 4.0 release announcement states:

This is the fourth major release of bash. This release fixes the remaining serious bugs in the bash version 3 branch and introduces significant new features. The most notable new features are associative arrays, improvements to the programmable completion functionality, case-modifying word expansions, co-processes, support for the '**' special glob pattern, and additions to the shell syntax and redirections. The shell has been changed to be more rigorous about parsing commands inside command substitutions, fixing one piece of Posix non-compliance.

A long list of new capabilities have been added to BASH, here are some of the highlights:

  • The new autocd option causes bash to change to the directory that is the first word in a command.
  • The new checkjobs option makes BASH report running and stopped jobs when it exits.
  • New shell variables include BASHPID (the BASH process ID), COMP_TYPE (type of completion) and COMP_KEY (completion invocation character).
  • BASH now supports a settable compatibility level for emulating older versions of the shell.
  • New ulimit options are available for setting the socket buffer size and the number of threads.
  • A new mapfile builtin can be used to populate an array with lines from a given file.
  • Limited support has been added for completing command name words with globbing characters.
  • The new globstar shell option allows ** to recursively match directories and files.
  • The new dirspell shell option makes the filename completion code perform spelling correction on directory names.
  • The read builtin's new -t option adds support for fractional timeout values.
  • The new &>> redirection operator appends both standard output and standard error to a named file.
  • Several new capabilities have been added to the case statement.
  • New uppercase (^[^]) and lowercase (,[,]) case-modifying word expansions are available.
  • Support has been added for associative array variables.
  • A new coproc reserved word can specify a coprocess, which is an asynchronous command run with two pipes connected to the creating shell.
  • A long list of new readline capabilities have been added.
  • Much more...

The latest version of BASH has acquired some of the advanced features found in newer projects such as the Z shell and the Python language. The user experience is enhanced and new capabilities are available for those who write BASH scripts. Hopefully the backwards-compatibility considerations have been adequately dealt with. BASH 4.0 shows that even an old dog can sometimes learn a few new tricks.


(Log in to post comments)

Bash 4.0 brings new capabilities

Posted Feb 27, 2009 10:40 UTC (Fri) by liljencrantz (subscriber, #28458) [Link]

Interesting. Some of the features in bash 4.0 seem to come from the fish shell. For example, the zsh '**' only matches directories while fish and bash match both files and directories. Fish has also had full support for completion of filenames containing globs and the autocd feature for a few years.

As the author of fish, I have to say it's nice to see some of it's features trickling down to bash as well.

Bash 4.0 brings new capabilities

Posted Mar 5, 2009 13:51 UTC (Thu) by mikachu (guest, #5333) [Link]

Actually, in zsh, ** by itself doesn't match directories recursively, only **/ does. **/* matches all files and subdirectories recursively. (And then of course you can do things like **/*(.) to match only files and not directories recursively.)

Bash 4.0 brings new capabilities

Posted Feb 28, 2009 3:42 UTC (Sat) by k8to (subscriber, #15413) [Link]

Features from python?

Bash 4.0 brings new capabilities

Posted Mar 15, 2009 1:32 UTC (Sun) by sigra (guest, #57156) [Link]

> Features from python?

"Support has been added for associative array variables."

Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds