TT#44516 Fix quoting logic for script 'set' for values like '10G'

It was impossible to set value like '10G' previosuly:

>> ngcpcfg set /etc/ngcp-config/config.yml bootenv.netscript.fallbackfssize=10M
> Bareword found where operator expected at /tmp/tmp.px3MpkUFZS line 28, near "10M"
>         (Missing operator before M?)
> Bareword found where operator expected at /tmp/tmp.px3MpkUFZS line 30, near "10M"
>         (Missing operator before M?)
> Bareword found where operator expected at /tmp/tmp.px3MpkUFZS line 31, near "10M"
>         (Missing operator before M?)
> Bareword found where operator expected at /tmp/tmp.px3MpkUFZS line 33, near "10M"
>         (Missing operator before M?)
> Bareword found where operator expected at /tmp/tmp.px3MpkUFZS line 34, near "10M"
>         (Missing operator before M?)
> syntax error at /tmp/tmp.px3MpkUFZS line 28, near "10M"
> syntax error at /tmp/tmp.px3MpkUFZS line 30, near "10M"
> syntax error at /tmp/tmp.px3MpkUFZS line 39, near "}"
> Execution of /tmp/tmp.px3MpkUFZS aborted due to compilation errors.

The 'case' statement doesn't support regular expresions in Bash,
let's rewrite them into linear check.

Change-Id: I29ced837fca0abdc3cbe1ea18c614c4c1dd6780c
changes/98/23698/5
Alexander Lutay 8 years ago
parent dfb0053b37
commit 203cdf9908

@ -44,17 +44,15 @@ log_debug "Saving option '${option}' value '${value}' into '${file}'"
if [[ ${value} =~ ^\'.*\'$ ]] ; then
log_debug "\$value is already quoted."
elif [[ ${value} =~ ^[0-9]*$ ]] ; then
log_debug "Not quoting \$value for integers."
elif [[ ${value} =~ ^\[.*\]$ ]] ; then
log_debug "Not quoting \$value for arrays."
elif [[ ${value} =~ ^\{.*\}$ ]] ; then
log_debug "Not quoting \$value for hashes."
else
log_debug "\$value is NOT quoted, doing so if necessary."
case ${value} in
[0-9]*|\[*\]|\{*\})
log_debug "Do not quoting \$value for integers, arrays and hashes."
;;
*)
log_debug "Quoting \$value to prevent further Perl errors."
value="\"${value}\""
;;
esac
log_debug "Quoting \$value to prevent further Perl errors."
value="\"${value}\""
fi
tmp=$(mktemp)

Loading…
Cancel
Save