* quoting arguments in a script
@ 2008-10-14 19:28 denis
2008-10-15 0:18 ` Phil Pennock
0 siblings, 1 reply; 3+ messages in thread
From: denis @ 2008-10-14 19:28 UTC (permalink / raw)
To: zsh-users
Hi,
I'm looking for a way to quote strings in a zsh script.
Consider the following example script which should be able to be
used exactly like the original grep:
#!/bin/zsh
emacsclient -e "(grep \"grep -nH $@\")"
This is not working because $@ breaks the string. Replacing $@
with $* won't be enough either.
Maybe it is possible to use the builtin function quote-line (M-')
for this?
Thanks in advance.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: quoting arguments in a script
2008-10-14 19:28 quoting arguments in a script denis
@ 2008-10-15 0:18 ` Phil Pennock
2008-10-15 17:58 ` denis
0 siblings, 1 reply; 3+ messages in thread
From: Phil Pennock @ 2008-10-15 0:18 UTC (permalink / raw)
To: denis; +Cc: zsh-users
On 2008-10-14 at 21:28 +0200, denis wrote:
> I'm looking for a way to quote strings in a zsh script.
>
> Consider the following example script which should be able to be
> used exactly like the original grep:
>
> #!/bin/zsh
> emacsclient -e "(grep \"grep -nH $@\")"
>
> This is not working because $@ breaks the string. Replacing $@
> with $* won't be enough either.
>
> Maybe it is possible to use the builtin function quote-line (M-')
> for this?
I don't know exactly what syntax you need, not knowing the other tools,
but you should probably be looking at something like:
${(q)^^@}
Or use ${(qq)^^@} if you want to see the results always quoted. The
(q), (qq), etc modifiers are documented in zshexpn(1) and quote the
results. The ^^ is to explicitly turn off rc_expand_param; you're not
running "#!/bin/zsh -f" so start-up files are an issue.
% function foo { print "foo ${(qq)^^@}" }
% foo a b c
foo 'a' 'b' 'c'
The single (q) should be sufficient.
To highlight the ^^, for me with rc_expand_param set, I get the same
results that you'd get if you used ^ (explicitly turn on; doubling is
explicit off instead of accepting default; this too is documented in
zshexpn(1) but it's something you need to know that you need to look
for).
% function foo { print "foo ${(qq)^@}" }
% foo a b c
foo 'a' foo 'b' foo 'c'
Regards,
-Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: quoting arguments in a script
2008-10-15 0:18 ` Phil Pennock
@ 2008-10-15 17:58 ` denis
0 siblings, 0 replies; 3+ messages in thread
From: denis @ 2008-10-15 17:58 UTC (permalink / raw)
To: Phil Pennock; +Cc: zsh-users
Phil Pennock wrote:
> On 2008-10-14 at 21:28 +0200, denis wrote:
> > I'm looking for a way to quote strings in a zsh script.
>
> you should probably be looking at something like:
>
> ${(q)^^@}
Thank you very much, that's what I was looking for.
Although it took me a while until I figured out how to accomplish
the whole task:
#!/bin/zsh
helper () {
emacsclient -e \
"(progn
(cd \"$PWD\")
(grep ${(qqq)${(q)@}}))"
}
helper grep -nH "$@"
The arguments have to be quoted twice. One level as the parameter
to emacsclient and another one for the parameters to the
grep-command.
And then I had the problem with appending the $@-arguments to
"grep -nH", why I added the helper-function.
Probably not the neatest way to do it, but it works.
Regards,
Denis
PS: If you are using emacs you should try the script. Grepping is
more fun if you can click the results :-)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-15 17:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-14 19:28 quoting arguments in a script denis
2008-10-15 0:18 ` Phil Pennock
2008-10-15 17:58 ` denis
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).