version 1.288, 2014/08/03 17:11:44 |
version 1.289, 2014/08/04 21:56:30 |
|
|
# eval "set -- $quotedlist" |
# eval "set -- $quotedlist" |
# or like this: |
# or like this: |
# eval "\$command $quotedlist \$filename" |
# eval "\$command $quotedlist \$filename" |
|
# |
shell_quote() |
shell_quote() |
{ |
{( |
local result='' |
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 |
for arg in "$@" ; do |
# Append a space if necessary |
case "${arg}" in |
result="${result}${result:+ }" |
'') |
# Convert each embedded ' to '\'', |
qarg="''" |
# then insert ' at the beginning of the first line, |
;; |
# and append ' at the end of the last line. |
*[!-./a-zA-Z0-9]*) |
result="${result}$(printf "%s\n" "$arg" | \ |
# Convert each embedded ' to '\'', |
sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")" |
# 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 |
done |
printf "%s\n" "$result" |
printf "%s\n" "$result" |
} |
)} |
|
|
statusmsg() |
statusmsg() |
{ |
{ |