Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
bash4 [2011/06/04 11:22] thebonsai 4.2 is available since... long |
bash4 [2018/02/03 07:52] (current) narutowindy [Bash 4 - a rough overview] |
||
---|---|---|---|
Line 3: | Line 3: | ||
:V4: | :V4: | ||
- | Beside many bugfixes since Bash 3.2, Bash 4 will bring some interesting new | + | <note>Attention: Since Bash 4 has been around for quite some time now (4.3 will come soon), I consider it to be "standard". This page is not maintained anymore and is left here to keep your links working. See the [[scripting:bashchanges]] page for new stuff introduced.</note> |
- | features for shell scripters and shell users. See also [[scripting:bashchanges]] for a small general overview. | + | |
- | Not all of the changes and news are written down here, just the biggest or | + | Besides many bugfixes since Bash 3.2, Bash 4 will bring some interesting new |
- | most interesting ones. Also the changes to completion and the readline component | + | features for shell users and scripters. See also [[scripting:bashchanges]] for a small general overview with more details. |
- | are not mentioned. **Though, if you're familiar with these parts of Bash (and Bash 4), | + | |
+ | Not all of the changes and news are included here, just the biggest or | ||
+ | most interesting ones. The changes to completion, and the readline component | ||
+ | are not covered. **Though, if you're familiar with these parts of Bash (and Bash 4), | ||
feel free to write a chapter here.** | feel free to write a chapter here.** | ||
Line 15: | Line 17: | ||
<WRAP center round download 60%> | <WRAP center round download 60%> | ||
- | The current available **stable** version is 4.2 release (February 13, 2011): | + | The current available **stable** version is 4.4.18 release (February 03, 2018): |
- | * ftp://ftp.cwru.edu/pub/bash/bash-4.2.tar.gz | + | * ftp://ftp.cwru.edu/pub/bash/bash-4.4.18.tar.gz |
- | * ftp://ftp.gnu.org/pub/gnu/bash/bash-4.2.tar.gz | + | * ftp://ftp.gnu.org/pub/gnu/bash/bash-4.4.18.tar.gz |
</WRAP> | </WRAP> | ||
Line 26: | Line 28: | ||
==== The new "coproc" keyword ==== | ==== The new "coproc" keyword ==== | ||
- | Bash 4 introduces the concepts of coprocesses, a well known feature in other | + | Bash 4 introduces the concepts of coprocesses, a well known feature of other |
shells. The basic concept is simple: It will start any command in the background | shells. The basic concept is simple: It will start any command in the background | ||
and set up an array that is populated with accessible files that represent the | and set up an array that is populated with accessible files that represent the | ||
Line 39: | Line 41: | ||
The ''mapfile'' builtin is able to map the lines of a file directly into an | The ''mapfile'' builtin is able to map the lines of a file directly into an | ||
- | array. This avoids to fill an array yourself using a loop. It allows to define | + | array. This avoids having to fill an array yourself using a loop. It enables you to define |
- | the range of lines to read and optionally calling a callback, for example to | + | the range of lines to read, and optionally call a callback, for example to |
display a progress bar. | display a progress bar. | ||
Line 62: | Line 64: | ||
functions, when used with ''-f''). The output is fully re-usable as input. | functions, when used with ''-f''). The output is fully re-usable as input. | ||
- | The new option ''-l'' declares a variable in a way that the content ist | + | The new option ''-l'' declares a variable in a way that the content is |
- | converted to lowercase on assignment. Same, but for uppercase, applies to | + | converted to lowercase on assignment. For uppercase, the same applies to |
''-u''. The option ''-c'' causes the content to be capitalized before | ''-u''. The option ''-c'' causes the content to be capitalized before | ||
assignment. | assignment. | ||
Line 71: | Line 73: | ||
==== Changes to the "read" builtin ==== | ==== Changes to the "read" builtin ==== | ||
- | The ''read'' builtin command got some interesting new features. | + | The ''read'' builtin command has some interesting new features. |
The ''-t'' option to specify a timeout value has been slightly tuned. It now | The ''-t'' option to specify a timeout value has been slightly tuned. It now | ||
accepts fractional values and the special value 0 (zero). When ''-t 0'' is | accepts fractional values and the special value 0 (zero). When ''-t 0'' is | ||
specified, ''read'' immediately returns with an exit status indicating if | specified, ''read'' immediately returns with an exit status indicating if | ||
- | there's data waiting or not. However, when a timeout is given and the ''read'' | + | there's data waiting or not. However, when a timeout is given, and the ''read'' |
builtin times out, any partial data recieved up to the timeout is stored in the | builtin times out, any partial data recieved up to the timeout is stored in the | ||
given variable, rather than lost. When a timeout is hit, ''read'' exits with a | given variable, rather than lost. When a timeout is hit, ''read'' exits with a | ||
Line 83: | Line 85: | ||
A new option, ''-i'', was introduced to be able to preload the input buffer with | A new option, ''-i'', was introduced to be able to preload the input buffer with | ||
some text (when Readline is used, with ''-e''). The user is able to change the | some text (when Readline is used, with ''-e''). The user is able to change the | ||
- | text or just press return to accept it. | + | text, or press return to accept it. |
See [[commands:builtin:read]] | See [[commands:builtin:read]] | ||
Line 97: | Line 99: | ||
==== Changes to the "ulimit" builtin ==== | ==== Changes to the "ulimit" builtin ==== | ||
- | Beside the use of the 512 bytes blocksize everywhere in POSIX mode, ''ulimit'' | + | Besides the use of the 512 bytes blocksize everywhere in POSIX mode, ''ulimit'' |
- | supports two new limits: ''-b'' for max. socket buffer size and ''-T'' for max. | + | supports two new limits: ''-b'' for max socket buffer size and ''-T'' for max |
number of threads. | number of threads. | ||
Line 105: | Line 107: | ||
==== Brace Expansion ==== | ==== Brace Expansion ==== | ||
- | The brace expancion was tuned to provide expansion results with leading zeros | + | The brace expansion was tuned to provide expansion results with leading zeros |
when requesting a row of numbers. | when requesting a row of numbers. | ||
Line 121: | Line 123: | ||
==== Substring expansion ==== | ==== Substring expansion ==== | ||
When using substring expansion on the positional parameters, a starting | When using substring expansion on the positional parameters, a starting | ||
- | index of 0 now causes $0 to be prefixed to the list (if the positional parameters are used at all). Before, this expansion | + | index of 0 now causes $0 to be prepended to the list (if the positional parameters are used). Before, this expansion |
started with $1: | started with $1: | ||
<code> | <code> | ||
Line 132: | Line 134: | ||
There's a new shell option ''[[internals:shell_options#globstar | globstar]]''. When enabled, Bash will perform | There's a new shell option ''[[internals:shell_options#globstar | globstar]]''. When enabled, Bash will perform | ||
recursive globbing on ''<nowiki>**</nowiki>'' -- this means it matches all directories and files | recursive globbing on ''<nowiki>**</nowiki>'' -- this means it matches all directories and files | ||
- | from the current position in the filesystem, rather that only the current level. | + | from the current position in the filesystem, rather than only the current level. |
The new shell option ''[[internals:shell_options#dirspell | dirspell]]'' enables spelling corrections on directory | The new shell option ''[[internals:shell_options#dirspell | dirspell]]'' enables spelling corrections on directory | ||
Line 141: | Line 143: | ||
===== Associative Arrays ===== | ===== Associative Arrays ===== | ||
- | Beside the classic method of integer indexed arrays, Bash 4 supports associative arrays. | + | Besides the classic method of integer indexed arrays, Bash 4 supports associative arrays. |
An associative array is an array indexed by an arbitrary string, something like | An associative array is an array indexed by an arbitrary string, something like | ||
Line 167: | Line 169: | ||
===== Interesting new shell variables ===== | ===== Interesting new shell variables ===== | ||
^Variable ^Description ^ | ^Variable ^Description ^ | ||
- | |''BASHPID'' | contains the PID of the current shell (this is different to what ''$$'' does!) | | + | |[[syntax:shellvars#BASHPID|BASHPID]] | contains the PID of the current shell (this is different than what ''$$'' does!) | |
- | |''PROMPT_DIRTRIM'' | specifies the max. level of unshortened pathname elements in the prompt | | + | |[[syntax:shellvars#PROMPT_DIRTRIM|PROMPT_DIRTRIM]] | specifies the max. level of unshortened pathname elements in the prompt | |
+ | |[[syntax:shellvars#FUNCNEST|FUNCNEST]] | control the maximum number of shell function recursions | | ||
See [[syntax:shellvars]] | See [[syntax:shellvars]] | ||
Line 181: | Line 184: | ||
|''[[internals:shell_options#dirspell | dirspell]]'' | enables spelling corrections on directory names during globbing | | |''[[internals:shell_options#dirspell | dirspell]]'' | enables spelling corrections on directory names during globbing | | ||
|''[[internals:shell_options#globstar | globstar]]'' | enables recursive globbing with ''<nowiki>**</nowiki>'' | | |''[[internals:shell_options#globstar | globstar]]'' | enables recursive globbing with ''<nowiki>**</nowiki>'' | | ||
+ | |''[[internals:shell_options#lastpipe | lastpipe]]'' | (4.2) to execute the last command in a pipeline in the current environment | | ||
+ | |||
See [[internals:shell_options]] | See [[internals:shell_options]] | ||
Line 188: | Line 193: | ||
* 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. This can be used to display userfriendly messages or perform different command searches | * 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. This can be used to display userfriendly messages or perform different command searches | ||
* The behaviour of the ''set -e'' (''errexit'') mode was changed, it now acts more intuitive (and is better documented in the manpage). | * The behaviour of the ''set -e'' (''errexit'') mode was changed, it now acts more intuitive (and is better documented in the manpage). | ||
- | * The output target for the ''xtrace'' (''set -x''/''set +x'') feature ist configurable **since Bash 4.1** (before it's fixed to ''stderr''): a variable named ''BASH_XTRACEFD'' can be set to the filedescriptor that should get the output | + | * The output target for the ''xtrace'' (''set -x''/''set +x'') feature is configurable **since Bash 4.1** (previously, it was fixed to ''stderr''): a variable named [[syntax:shellvars#BASH_XTRACEFD|BASH_XTRACEFD]] can be set to the filedescriptor that should get the output |
- | * Bash 4.1 is able to log the history to syslog | + | * Bash 4.1 is able to log the history to syslog (only to be enabled at compile time in ''config-top.h'') |