Bash-4.0 introduced the concept of a ‘shell compatibility level’, specified
as a set of options to the shopt builtin
and so on).
There is only one current
compatibility level – each option is mutually exclusive.
The compatibility level is intended to allow users to select behavior
from previous versions that is incompatible with newer versions
while they migrate scripts to use current features and
behavior. It’s intended to be a temporary solution.
This section does not mention behavior that is standard for a particular
version (e.g., setting
compat32 means that quoting the rhs of the regexp
matching operator quotes special regexp characters in the word, which is
default behavior in bash-3.2 and above).
If a user enables, say,
compat32, it may affect the behavior of other
compatibility levels up to and including the current compatibility level.
The idea is that each compatibility level controls behavior that changed
in that version of Bash,
but that behavior may have been present in earlier versions.
For instance, the change to use locale-based comparisons with the
command came in bash-4.1, and earlier versions used ASCII-based comparisons,
compat32 will enable ASCII-based comparisons as well.
That granularity may not be sufficient for
all uses, and as a result users should employ compatibility levels carefully.
Read the documentation for a particular feature to find out the
Bash-4.3 introduced a new shell variable:
The value assigned
to this variable (a decimal version number like 4.2, or an integer
corresponding to the
compatNN option, like 42) determines the
Starting with bash-4.4, Bash has begun deprecating older compatibility
Eventually, the options will be removed in favor of
Bash-5.0 is the final version for which there will be an individual shopt
option for the previous version. Users should use
on bash-5.0 and later versions.
The following table describes the behavior changes controlled by each
compatibility level setting.
compatNN tag is used as shorthand for setting the
to NN using one of the following mechanisms.
For versions prior to bash-5.0, the compatibility level may be set using
compatNN shopt option.
For bash-4.3 and later versions, the
BASH_COMPAT variable is preferred,
and it is required for bash-5.1 and later versions.
[[command’s regexp matching operator (=~) has no special effect
[[command do not consider the current locale when comparing strings; they use ASCII ordering. Bash versions prior to bash-4.1 use ASCII collation and strcmp(3); bash-4.1 and later use the current locale’s collation sequence and strcoll(3).
timemay be followed by options and still be recognized as a reserved word (this is POSIX interpretation 267)
continuein that function will break or continue loops in the calling context. Bash-4.4 and later reset the loop state to prevent this
BASH_ARGCso they can expand to the shell’s positional parameters even if extended debugging mode is not enabled
continuewill cause the subshell to exit. Bash-5.0 and later reset the loop state to prevent the exit
readonlythat set attributes continue to affect variables with the same name in the calling environment even if the shell is not in posix mode
compat50 (set using BASH_COMPAT)
$RANDOMis generated to introduce slightly more randomness. If the shell compatibility level is set to 50 or lower, it reverts to the method from bash-5.0 and previous versions, so seeding the random number generator by assigning a value to
RANDOMwill produce the same sequence as in bash-5.0