Hello.
Harvey wrote in
<[email protected]>:
|Sorry, posted the wrong version of the pack_args() funtion:
|I have payed with possible solutions for so long that I forgot the
|restore the original before posting -blush-
|
|Here is the original version:
|------------------------------------------------------------------------
|
|# Packs arguments into a single string.
|#
|# Input:
|# $1 = name of variable receiving the arguments in such a way that
|# (re)evaluating them provides the original arguments
|# $2... = arguments
Dunno about yours, but Robert Elz (kre) did such in a way that is
portable to any shell i tried it with (// is definitely not
portable); with only slight changes of mine, as attached.
|# Example:
|# func() {
|# local args
|# pack_args args "$@"
|# send_rpc func_impl "$args"
|# }
|# # (in another process)
|# receive_rpc() {
|# local func="$1"
|# local args="$2"
|# eval $func "$args"
|# }
|pack_args()
|{
| local _p _resvar=$1 _result= _value
| shift
| for _p
| do
| _result="$_result '${_p//'/'\"'\"'}'"
| done
| eval $_resvar=\${_result\# }
|}
--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)
#!/bin/sh -
#@ Round trip quote strings in POSIX shell. For example
#@ 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).
# 2017 - 2022 Steffen Nurpmeso <[email protected]>.
# Public Domain
# 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
)
# s-sht-mode
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox