set-var(): Check input, die on errors
Previously, set_var() had no input checking, combined with the point that, via vars, set_var() is user facing, this can lead to easy user errors. Now, input is checked: - Parameter 1 is required. - Parameter 1 cannot contain a space. - Less-than 3 input parameters are expected. - Quote the expansion of the first occurence of parameter 1 in the evaluated expression. Signed-off-by: Richard T Bonhomme <tincantech@protonmail.com>
This commit is contained in:
parent
d167b517f7
commit
66d282e1c1
@ -4345,10 +4345,10 @@ Sourcing the vars file and building certificates will probably fail ..'
|
|||||||
# the variable when it is already defined (even if currently null)
|
# the variable when it is already defined (even if currently null)
|
||||||
# Sets $1 as the value contained in $2 and exports (may be blank)
|
# Sets $1 as the value contained in $2 and exports (may be blank)
|
||||||
set_var() {
|
set_var() {
|
||||||
var=$1
|
[ "$1" ] || die "set_var - missing input"
|
||||||
shift
|
[ "$1" = "${1% *}" ] || die "set_var - input error"
|
||||||
value="$*"
|
[ "$#" -lt 3 ] || die "set_var - excess input"
|
||||||
eval "export $var=\"\${$var-$value}\""
|
eval "export \"$1\"=\"\${$1-$2}\""
|
||||||
} #=> set_var()
|
} #=> set_var()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user