tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Proposal to add /usr/bin/shquote
On Sat, Sep 06, 2008 at 05:06:55PM +0200, Alan Barrett wrote:
>
> However, it requires the save_args function to be cut and pasted into
> every script that wants it (or made available via a library of shell
> functions).
Easier than getting an extra executuble into $PATH :-)
> ssh_cmd="$( shquote ssh user@host "$remote_cmd" )"
ssh is a bad example, I suspect everything needs quoting twice, once
for the local system and once for the remote one!
So, process each arg and replace every ' with '"'"' and insert inside '.
Something like:
save_args() {
local a n v IFS;
v=; n=$1; shift
for a; do
v="$v '"
IFS="'"; set -- $a; IFS=
while [ $# -gt 1 ]; do
v="$v$1'"'"'"'"'"'"'"
shift;
done
v="$v$1'"
done
eval $n=\"\$v\"
}
David
--
David Laight: david%l8s.co.uk@localhost
Home |
Main Index |
Thread Index |
Old Index