diff options
| author | apb <apb@NetBSD.org> | 2014-08-04 21:56:30 +0000 |
|---|---|---|
| committer | apb <apb@NetBSD.org> | 2014-08-04 21:56:30 +0000 |
| commit | 2dd73bdfb8ffc2ffd45bb75e3c938dccc6c929bf (patch) | |
| tree | e9bf566aa6b419341393afd8ccc75d717b053f35 /build.sh | |
| parent | 465b0d3ef8dc52768488795fd0adec19fb7280a7 (diff) | |
Synchronise several shell_quote implementations, and:
* Elide some unnecessary pairs of quotation marks, to improve readability.
For example, shell_quote "''" is now \'\' instead of ''\'''\'''.
* Don't add quotes around words that contain only safe characters,
to improve readability.
* LC_COLLATE=C to prevent [a-zA-Z] from matching non-ASCII characters.
* Use ${SED} if defined.
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 46 |
1 files changed, 34 insertions, 12 deletions
@@ -1,5 +1,5 @@ #! /usr/bin/env sh -# $NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $ +# $NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $ # # Copyright (c) 2001-2011 The NetBSD Foundation, Inc. # All rights reserved. @@ -286,21 +286,43 @@ ERRORMESSAGE # eval "set -- $quotedlist" # or like this: # eval "\$command $quotedlist \$filename" +# shell_quote() -{ +{( local result='' - local arg + local arg qarg + LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII for arg in "$@" ; do - # Append a space if necessary - result="${result}${result:+ }" - # Convert each embedded ' to '\'', - # then insert ' at the beginning of the first line, - # and append ' at the end of the last line. - result="${result}$(printf "%s\n" "$arg" | \ - sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")" + case "${arg}" in + '') + qarg="''" + ;; + *[!-./a-zA-Z0-9]*) + # Convert each embedded ' to '\'', + # then insert ' at the beginning of the first line, + # and append ' at the end of the last line. + # Finally, elide unnecessary '' pairs at the + # beginning and end of the result and as part of + # '\'''\'' sequences that result from multiple + # adjacent quotes in he input. + qarg="$(printf "%s\n" "$arg" | \ + ${SED:-sed} -e "s/'/'\\\\''/g" \ + -e "1s/^/'/" -e "\$s/\$/'/" \ + -e "1s/^''//" -e "\$s/''\$//" \ + -e "s/'''/'/g" + )" + ;; + *) + # Arg is not the empty string, and does not contain + # any unsafe characters. Leave it unchanged for + # readability. + qarg="${arg}" + ;; + esac + result="${result}${result:+ }${qarg}" done printf "%s\n" "$result" -} +)} statusmsg() { @@ -1774,7 +1796,7 @@ createmakewrapper() eval cat <<EOF ${makewrapout} #! ${HOST_SH} # Set proper variables to allow easy "make" building of a NetBSD subtree. -# Generated from: \$NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $ +# Generated from: \$NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $ # with these arguments: ${_args} # |
