set_var(): Allow empty input to return without error

Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
This commit is contained in:
Richard T Bonhomme 2023-07-03 02:04:18 +01:00
parent 002c84fff1
commit 8e62fa28d7
No known key found for this signature in database
GPG Key ID: 2D767DB92FB6C246

View File

@ -5762,9 +5762,9 @@ Temporary directory does not exist:
# the variable when it is already defined (even if currently null)
# Sets $1 as the value contained in $2 and exports (may be blank)
set_var() {
[ "$1" ] || die "set_var - missing input"
[ "$1" = "${1% *}" ] || die "set_var - input error"
[ "$#" = 0 ] && return
[ "$#" -lt 3 ] || die "set_var - excess input"
[ "$1" = "${1% *}" ] || die "set_var - input error"
eval "export \"$1\"=\"\${$1-$2}\""
} #=> set_var()