trondd wrote in <[email protected]\
chi.com>:
|On Sun, November 3, 2019 12:02 pm, trondd wrote:
|> On Sun, November 3, 2019 6:27 am, Florian Obser wrote:
|>> On Sun, Nov 03, 2019 at 12:21:59PM +0100, Antoine Jacoutot wrote:
|>>> On Sun, Nov 03, 2019 at 12:16:56PM +0100, Florian Obser wrote:
...
|I've tested the diff and it works as expected in my environment. I don't
|need a username and password for proxy access but it populates the
|rc.firsttime file fine.
|
|The quote() function is actually pretty simple.
|
|quote() (
| # Since this is a subshell we won't pollute the calling namespace.
| for _a; do
| # alias string to Q, does escaping and quoting
| alias Q=$_a;
| # set variable back to value of alias
| _a=$(alias Q);
| # print variable, chopping off alias definition
| # no newline, don't substitute the escape sequences
| # we made above
| print -rn -- " ${_a#Q=}"
| done | sed '1s/ //'
| echo
|)
I felt a bit undecided from your first mail on, maybe also because
of your mailer, but wanted to post the all-compatible all-shell
quote of and from Robert Elz here.
#@ Round trip quote strings in POSIX shell. E.g.,
#@ set -- x 'a \ b' "foo'" "\\'b\\a\\r\\" AƤ
#@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
#@ saved_parameters=`quote_rndtrip "$@"`
#@ eval "set -- $saved_parameters"
#@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
#
# 2017 Robert Elz (kre).
...
# Though slower use a subshell version instead of properly restoring $IFS
# and flags, as elder shells may not be able to properly restore flags via
# "set +o" as later standardized in POSIX, and it seems overkill to handle
# all possible forms of output "set +o" may or may not actually generate.
quote__rndtrip() (
case "$1" in
*\'*) ;;
*) printf "'%s'" "$1"; return 0;;
esac
a="$1" s= e=
while case "$a" in
\'*) a=${a#?}; s="${s}\\\\'";;
*\') a=${a%?}; e="${e}\\\\'";;
'') printf "${s}${e}"; exit 0;;
*) false;;
esac
do
continue
done
IFS=\'
set -f
set -- $a
r="${1}"
shift
for a
do
r="${r}'\\''${a}"
done
printf "${s}'%s'${e}" "${r}"
exit 0
)
quote_rndtrip() (
j=
for i
do
[ -n "$j" ] && printf ' '
j=' '
quote__rndtrip "$i"
done
)
quote_string() (
j=
for i
do
[ -n "$j" ] && printf '\\ '
j=' '
quote__rndtrip "$i"
done
)
|$ export "test=fancy ' stuff #and not a comment"
|$ ./quote.ksh
|$ cat test.out
|
|export 'http_proxy=fancy '\'' stuff #and not a comment'
|
|$ export "test=even
|> this works #"
|$ ./quote.ksh
|$ cat test.out
|
|export 'http_proxy=even
|this works #'
Of course, if in install.sub there is already your quote function,
that surely is preferred.
Good night,
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)