mirror of
https://github.com/ARMmbed/mbedtls.git
synced 2025-05-12 18:04:39 +08:00
Improve simplified quoting
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
bdf0a6d431
commit
dbc2e8d4cc
@ -27,18 +27,15 @@ print_quoted_args() {
|
|||||||
# similar to printf '%q' "$@"
|
# similar to printf '%q' "$@"
|
||||||
# but produce more human-readable results for common/simple cases like "a b"
|
# but produce more human-readable results for common/simple cases like "a b"
|
||||||
for a in "$@"; do
|
for a in "$@"; do
|
||||||
simple_pattern='^([[:alnum:]_+-]+=)?([[:alnum:] _=+-./:@]*)$'
|
# Get bash to quote the string
|
||||||
if [[ $a =~ ' ' && $a =~ $simple_pattern ]]; then
|
q=$(printf '%q' "$a")
|
||||||
# a has spaces, but no other special characters that need escaping
|
simple_pattern="^([-[:alnum:]_+./:@]+=)?([^']*)$"
|
||||||
# (quoting after removing spaces yields no backslashes)
|
if [[ "$a" != "$q" && $a =~ $simple_pattern ]]; then
|
||||||
# simplify quoted form - e.g.:
|
# a requires some quoting (a != q), but has no single quotes, so we can
|
||||||
# a b -> "a b"
|
# simplify the quoted form - e.g.:
|
||||||
# CFLAGS=a b -> CFLAGS="a b"
|
# a b -> 'a b'
|
||||||
q="${BASH_REMATCH[1]}\"${BASH_REMATCH[2]}\""
|
# CFLAGS=a b -> CFLAGS='a b'
|
||||||
else
|
q="${BASH_REMATCH[1]}'${BASH_REMATCH[2]}'"
|
||||||
# get bash to do the quoting (which may result in no quotes or escaping,
|
|
||||||
# if none is needed).
|
|
||||||
q=$(printf '%q' "$a")
|
|
||||||
fi
|
fi
|
||||||
printf "%s " "$q"
|
printf "%s " "$q"
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user