New Features in Bash-4.0

The first public release of bash-4.0 is now available here at, and from the usual GNU mirror sites. Unlike previous bash distributions, this released file includes the formatted documentation (postscript, dvi, html, and nroffed versions of the manual pages). Diffs from bash-3.2 are not available.This is the fourth major release of bash. It 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.

This is a general description of the new features added to bash-4.0 since the release of bash-3.2. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

  1. When using substring expansion on the positional parameters, a starting index of 0 now causes $0 to be prefixed to the list.
  2. The `help’ builtin now prints its columns with entries sorted vertically rather than horizontally.
  3. There is a new variable, $BASHPID, which always returns the process id of the current shell.
  4. There is a new `autocd’ option that, when enabled, causes bash to attempt to `cd’ to a directory name that is supplied as the first word of a simple command.
  5. There is a new `checkjobs’ option that causes the shell to check for and report any running or stopped jobs at exit.
  6. The programmable completion code exports a new COMP_TYPE variable, set to a character describing the type of completion being attempted.
  7. The programmable completion code exports a new COMP_KEY variable, set to the character that caused the completion to be invoked (e.g., TAB).
  8. If creation of a child process fails due to insufficient resources, bash will try again several times before reporting failure.
  9. The programmable completion code now uses the same set of characters as readline when breaking the command line into a list of words.
  10. The block multiplier for the ulimit -c and -f options is now 512 when in Posix mode, as Posix specifies.
  11. Changed the behavior of the read builtin to save any partial input received in the specified variable when the read builtin times out.This also results in variables specified as arguments to read to be set to the empty string when there is no input available.When the read builtin times out, it returns an exit status greater than 128.
  12. The shell now has the notion of a `compatibility level’, controlled by new variables settable by `shopt’.Setting this variable currently restores the bash-3.1 behavior when processing quoted strings on the rhs of the `=~’ operator to the `[[‘ command.
  13. The `ulimit’ builtin now has new -b (socket buffer size) and -T (number of threads) options.
  14. The -p option to `declare’ now displays all variable values and attributes (or function values and attributes if used with -f).
  15. There is a new `compopt’ builtin that allows completion functions to modify completion options for existing completions or the completion currently being executed.
  16. The `read’ builtin has a new -i option which inserts text into the reply buffer when using readline.
  17. A new `-E’ option to the complete builtin allows control of the default behavior for completion on an empty line.
  18. There is now limited support for completing command name words containing globbing characters.
  19. Changed format of internal help documentation for all builtins to roughly follow man page format.
  20. The `help’ builtin now has a new -d option, to display a short description, and a -m option, to print help information in a man page-like format.
  21. There is a new `mapfile’ builtin to populate an array with lines from a given file.The name `readarray’ is a synonym.
  22. If a command is not found, the shell attempts to execute a shell function named `command_not_found_handle’, supplying the command words as the function arguments.
  23. There is a new shell option: `globstar’.When enabled, the globbing code treats `**’ specially — it matches all directories (and files within them, when appropriate) recursively.
  24. There is a new shell option: `dirspell’.When enabled, the filename completion code performs spelling correction on directory names during completion.
  25. The `-t’ option to the `read’ builtin now supports fractional timeout values.
  26. Brace expansion now allows zero-padding of expanded numeric values and will add the proper number of zeroes to make sure all values contain the same number of digits.
  27. There is a new bash-specific bindable readline function: `dabbrev-expand’. It uses menu completion on a set of words taken from the history list.
  28. The command assigned to a key sequence with `bind -x’ now sets two new variables in the environment of the executed command:READLINE_LINE_BUFFER and READLINE_POINT.The command can change the current readline line
  29. and cursor position by modifying READLINE_LINE_BUFFER and READLINE_POINT, respectively.
  30. There is a new &>> redirection operator, which appends the standard output and standard error to the named file.
  31. The parser now understands `|&’ as a synonym for `2>&1 |’, which redirects the standard error for a command through a pipe.
  32. The new `;&’ case statement action list terminator causes execution to continue with the action associated with the next pattern in the statement rather than terminating the command.
  33. The new `;;&’ case statement action list terminator causes the shell to test the next set of patterns after completing execution of the current action, rather than terminating the command.
  34. The shell understands a new variable: PROMPT_DIRTRIM.When set to an integer value greater than zero, prompt expansion of w and Wwill retain only that number of trailing pathname components and replace
  35. the intervening characters with `…’.
  36. There are new case-modifying word expansions: uppercase (^[^]) and lowercase (,[,]).They can work on either the first character or array element, or globally.They accept an optional shell pattern that determines which characters to modify.There is an optionally-configured feature to include capitalization operators.
  37. The shell provides associative array variables, with the appropriate support to create, delete, assign values to, and expand them.
  38. The `declare’ builtin now has new -l (convert value to lowercase upon assignment) and -u (convert value to uppercase upon assignment) options. There is an optionally-configurable -c option to capitalize a value at
  39. assignment.
  40. There is a new `coproc’ reserved word that specifies a coprocess: an asynchronous command run with two pipes connected to the creating shell. Coprocs can be named.The input and output file descriptors and the
  41. PID of the coprocess are available to the calling shell in variables with coproc-specific names.
  42. A value of 0 for the -t option to `read’ now returns success if there is input available to be read from the specified file descriptor.
  43. CDPATH and GLOBIGNORE are ignored when the shell is running in privileged mode.
  44. New bindable readline functions shell-forward-word and shell-backward-word, which move forward and backward words delimited by shell metacharacters and honor shell quoting.
  45. New bindable readline functions shell-backward-kill-word and shell-kill-word
  46. which kill words backward and forward, but use the same word boundaries as shell-forward-word and shell-backward-word.
Share Button

3 thoughts on “New Features in Bash-4.0

  1. This is an awesome entry. Thank you very much for the excellent post provided! I was looking for this entry for a long time

  2. Hello,

    Is there a way to capture the exit status of multiple child processes that have are being run in the background in parallel?

    The idea is to have a limit on the number of child processes being run in the background, determine their exit status, and re-run them if they fail.

    I am having a hard-time with this with the earlier versions of bash…

    Thanks very much for any tips that you could provide!

  3. @Sirisha, I just tried wait, looks it meet your needs well. When it returns, the exit code of the process is returned in the variable $?, hereis an example:

    joseph$ ( sleep 10; unknown-command ) &
    [1] 23527
    joseph$ -bash: line 91: unknown-command: command not found
    [1]+ Exit 127 ( sleep 10; unknown-command )
    joseph$ wait 23535
    joseph$ echo $?

Leave a comment

Your email address will not be published. Required fields are marked *