On 25/05/15 20:33, d...@yost.com wrote: > if [[ -n $ZSH_VERSION ]] ; then > echo "[ ${(q)@} ]" > eval ${(q)@} > else > echo "[ $@ ]" > eval $@ > fi I believe the bash equivalent here would be something along the lines of:
quoted=$(printf '%q ' "$@") quoted=${quoted% } echo "[ $quoted ]" eval "$quoted" You mention that bash is "unable to expand a variable with quoting intact", but nor is zsh. Zsh and bash can only quote a variable so that it won't break when used as an argument, but there is no way to retrieve the original quoting once it has been parsed by the shell. Usually if you want to pass around executable bash code you should do it in one already properly-quoted string that gets passed around in a single argument. Quoting the string (as we're having to do as part of "echodo") might be better off as another function. You already have zsh and bash cases, and I've seen some 'clever' shell quoting tricks at http://www.etalabs.net/sh_tricks.html which should work across pretty much every bourne-like shell under the sun.