If you want use Lobash with Bash 4.3 and lower versions, there are some knowledges you should know.
This section only show the compatibilities with different Bash versions.
There is a list of which features were added to specific releases (versions) of Bash.
Completely supported.
shopt -s inherit_errexit
is a new feature in Bash v4.4. There is no workaround in v4.3.declare -p
has a bug. See ./module-usages/condition.md#is_array and ./module-usages/condition.md#is_exported.- You should always declare a variable with initialization, like
declare -a var=()
,local var=
,export var=
instead ofdeclare -a var
,local var
,export var
.
- You should always declare a variable with initialization, like
- Only with bash 4.3, when
declare -a a
, thedeclare -p a
showsdeclare: a: not found
. readarray: -d: invalid option
util 4.4.
- The Nameref is new feature in Bash v4.3. Use
eval
as workaround. declare -p
has a bug. See ./module-usages/condition.md#is_exported.- You should always declare a variable with initialization, like
declare -a var=()
,local var=
,export var=
instead ofdeclare -a var
,local var
,export var
.
- You should always declare a variable with initialization, like
readarray: -d: invalid option
util 4.4.- For associative array,
[[ -v array[key] ]]
andtest -v array[key]
always be1
util 4.3.
declare -g var=str
not supported util v4.2, useread -r var <<< "str"
instead.$(( "$i" + 1 ))
not work in Bash 4.1, use$(( i + 1))
instead.[[ $'\e' == $'\u001b' ]]
isfalse
in Bash less than v4.2. No workaround.printf "%($1)T\\n" "-1"
not work in v4.1. No workaround.declare -p
has a bug. See ./module-usages/condition.md#is_exported.- You should always declare a variable with initialization, like
declare -a var=()
,local var=
,export var=
instead ofdeclare -a var
,local var
,export var
.
- You should always declare a variable with initialization, like
readarray: -d: invalid option
util 4.4.- For associative array,
[[ -v array[key] ]]
andtest -v array[key]
always be1
util 4.3.
-
exec {_sleep_fd}<> <(true)
is not supported util v4.1. No workaround. -
declare -p
has a bug. See ./module-usages/condition.md#is_exported.- You should always declare a variable with initialization, like
declare -a var=()
,local var=
,export var=
instead ofdeclare -a var
,local var
,export var
.
- You should always declare a variable with initialization, like
-
readarray: -d: invalid option
util 4.4. -
For associative array,
[[ -v array[key] ]]
andtest -v array[key]
always be1
util 4.3. -
Empty
$@
and$*
will throw error "unbound variable" withset -u
in v4.0. It is a bug of Bash. See https://unix.stackexchange.com/a/16565
Lobash not test with Bash 4.0 in MacOS and Linux. It seems a bug of Bash 4.0. Please contact me if you solved this problem.
To reproduce the problem for Linux,
# For Linux
> BASHVER=4.0 ./tools/test
malloc: hashlib.c:306: assertion botched
free: called with unallocated block argument
To reproduce the problem for MacOS,
# For MacOS
> BASHVER=4.0 ./tools/test
bash(38696,0x7fff989c2380) malloc: *** error for object 0x1061ad800: pointer being freed was not allocated
Lobash will not include modules whose metadata Bash
higher than target Bash version when build.
You can implement similar functions by reading Lobash source codes as references.
Nothing else.
Because there is no workaround and similar mechanism for fast-failing (inherit_errexit), it is your responsibility to keep the program always on right processing. Test your script with complete boundary testings. Make sure your script never get unexpected trapped.
Still add this line (shopt -p inherit_errexit &>/dev/null) && shopt -s inherit_errexit
to
your script to keep compatible with higher versions.
Same to 4.3.
Same to 4.3.
Same to 4.3.