2 #@ Round trip quote strings in POSIX shell. E.g.,
3 #@ set -- x 'a \ b' "foo'" "\\'b\\a\\r\\" AƤ
4 #@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
5 #@ saved_parameters=`quote_rndtrip "$@"`
6 #@ eval "set -- $saved_parameters"
7 #@ printf "%s: <%s><%s><%s><%s><%s>\n" "$#" "${1}" "${2}" "${3}" "$4" "$5"
9 # 2017 Robert Elz (kre).
10 # 2017 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
13 # Though slower use a subshell version instead of properly restoring $IFS
14 # and flags, as elder shells may not be able to properly restore flags via
15 # "set +o" as later standardized in POSIX, and it seems overkill to handle
16 # all possible forms of output "set +o" may or may not actually generate.
20 *) printf "'%s'" "$1"; return 0;;
24 \'*) a
=${a#?}; s
="${s}\\\\'";;
25 *\') a
=${a%?}; e
="${e}\\\\'";;
26 '') printf "${s}${e}"; exit 0;;
41 printf "${s}'%s'${e}" "${r}"
49 [ -n "$j" ] && printf ' '
59 [ -n "$j" ] && printf '\\ '