* converting parameter to words
@ 2000-10-13 15:48 Jack McKinney
2000-10-13 16:16 ` Nemeth Ervin
0 siblings, 1 reply; 5+ messages in thread
From: Jack McKinney @ 2000-10-13 15:48 UTC (permalink / raw)
To: zsh-users
-----BEGIN PGP SIGNED MESSAGE-----
I have a script that I want to pass multiple arguments to. These
arguments, however, need to appear with a '-r' in front of them in the
command executed inside the script. For example, if I do this:
$ example this that other
The script will need to execute
command -r this -r that -r other
One thought on this was:
#!/bin/zsh
for i
do
temp="$temp -r $i"
done
command $temp
Of course, this doesn't work because zsh passing the string inside
$temp as a single argument to the program, instead of parsing it for
words. From the man page, it sounds like ${^temp} or ${=temp} should
work, but neither does.
- --
"Restore your inalienable human rights. Jack McKinney
Vote Libertarian. http://www.lp.org http://www.lorentz.com
http://www.harrybrowne2000.org
F4 A0 65 67 58 77 AF 9B FC B3 C5 6B 55 36 94 A6 jackmc@lorentz.com
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBOecuukZx0BGJTwrZAQH/6AP/bVpZf0bL4rivlVLVAaSeI+DHbq4z5860
qx6RxhNJWOZSfmlv00F+XrVG6iOogr8tQ9V74QkIY6MssA7QVmpOcFCYYIdyfu9V
RFftK1PgvcUzwAO+qUmzpWySjxMWAuYY5Wr5UYJQjg/mmpwVDZ/fWY9DW4Wnrshn
pwrS9eRgUEE=
=u3lq
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: converting parameter to words
2000-10-13 15:48 converting parameter to words Jack McKinney
@ 2000-10-13 16:16 ` Nemeth Ervin
2000-10-13 18:23 ` Bart Schaefer
2000-10-13 19:53 ` Jack McKinney
0 siblings, 2 replies; 5+ messages in thread
From: Nemeth Ervin @ 2000-10-13 16:16 UTC (permalink / raw)
To: Jack McKinney; +Cc: zsh-users
Hi,
"Jack McKinney" <jackmc-zsh-users@lorentz.com> writes:
[...]
> #!/bin/zsh
>
> for i
> do
> temp="$temp -r $i"
> done
>
> command $temp
for i in ...
do
temp=("$temp[@]" -r "$i")
done
command "$temp[@]"
HTH,
--
Ervin
"Intelligenti pauca."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: converting parameter to words
2000-10-13 16:16 ` Nemeth Ervin
@ 2000-10-13 18:23 ` Bart Schaefer
2000-10-13 20:02 ` Jack McKinney
2000-10-13 19:53 ` Jack McKinney
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2000-10-13 18:23 UTC (permalink / raw)
To: Jack McKinney, zsh-users
On Oct 13, 10:48am, Jack McKinney wrote:
}
} for i
} do
} temp="$temp -r $i"
} done
}
} command $temp
}
} From the man page, it sounds like ${^temp} or ${=temp} should
} work, but neither does.
${=temp} should have done it for you:
zagzig[562] x="foo -r bar -r baz"
zagzig[563] print -l ${=x}
foo
-r
bar
-r
baz
However, it would do the wrong thing if any of the original arguments
contained whitespace.
On Oct 13, 6:16pm, Nemeth Ervin wrote:
}
} for i in ...
} do
} temp=("$temp[@]" -r "$i")
} done
}
} command "$temp[@]"
This is the right idea. Unless you have shwordsplit set (which you must
not, or you wouldn't have needed ${=temp} in the first place) you don't
even need the quotes that Nemeth used; and unless you have shortloops
turned off you can just write it like this:
local temp i
for i; temp=($temp -r $i)
command $temp
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: converting parameter to words
2000-10-13 16:16 ` Nemeth Ervin
2000-10-13 18:23 ` Bart Schaefer
@ 2000-10-13 19:53 ` Jack McKinney
1 sibling, 0 replies; 5+ messages in thread
From: Jack McKinney @ 2000-10-13 19:53 UTC (permalink / raw)
To: zsh-users
-----BEGIN PGP SIGNED MESSAGE-----
Big Brother tells me that Nemeth Ervin wrote:
>
> Hi,
>
>
> for i in ...
> do
> temp=("$temp[@]" -r "$i")
> done
>
> command "$temp[@]"
Didn't work 8-(.
- --
"Restore your inalienable human rights. Jack McKinney
Vote Libertarian. http://www.lp.org http://www.lorentz.com
http://www.harrybrowne2000.org
F4 A0 65 67 58 77 AF 9B FC B3 C5 6B 55 36 94 A6 jackmc@lorentz.com
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBOedoQ0Zx0BGJTwrZAQEpHwQAgtjt+K/itVQGrE/NSi04HsCpPLR3ukNt
v/FSGVikESWRpixqelEaypw46f6ukuNc/p3+AeEmfpNZLI8IW439xRHg1i7Sa/7D
1/BMvDbwUL9YwKra2R7kOcw1IOJ4/zi9XV0qGgOtzp2feFMSwM8+qIm8YR7U67tl
ek5hgHT6Bxc=
=gkb3
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: converting parameter to words
2000-10-13 18:23 ` Bart Schaefer
@ 2000-10-13 20:02 ` Jack McKinney
0 siblings, 0 replies; 5+ messages in thread
From: Jack McKinney @ 2000-10-13 20:02 UTC (permalink / raw)
To: zsh-users
-----BEGIN PGP SIGNED MESSAGE-----
Big Brother tells me that Bart Schaefer wrote:
> On Oct 13, 10:48am, Jack McKinney wrote:
> }
> } for i
> } do
> } temp="$temp -r $i"
> } done
> }
> } command $temp
> }
> } From the man page, it sounds like ${^temp} or ${=temp} should
> } work, but neither does.
>
> ${=temp} should have done it for you:
>
> zagzig[562] x="foo -r bar -r baz"
> zagzig[563] print -l ${=x}
Yep... this did it. I found another bone-headed error in the script
that was causing the real problem.
- --
"Restore your inalienable human rights. Jack McKinney
Vote Libertarian. http://www.lp.org http://www.lorentz.com
http://www.harrybrowne2000.org
F4 A0 65 67 58 77 AF 9B FC B3 C5 6B 55 36 94 A6 jackmc@lorentz.com
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2
iQCVAwUBOedqbkZx0BGJTwrZAQG2FwQAhImbPTBIKB8lSNGQeGBpIQ8hiE+d6vXx
5GSgL827sA/YWNc0mJqSVkYSRyNp+aLckHpMI7PWHFAp/aBHrT8DDeuX43GtIWfw
zek+krAz50DsqEC24zkhz1ia9W+peAn8EooarnSH9JkJhPObhChKvg0yJ/vmIjO/
F/kSil5k3a4=
=lW0a
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2000-10-13 20:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-13 15:48 converting parameter to words Jack McKinney
2000-10-13 16:16 ` Nemeth Ervin
2000-10-13 18:23 ` Bart Schaefer
2000-10-13 20:02 ` Jack McKinney
2000-10-13 19:53 ` Jack McKinney
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).