Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: quoting arguments in a script
- X-seq: zsh-users 13329
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: denis <mu_kuh@xxxxxxxx>
- Subject: Re: quoting arguments in a script
- Date: Tue, 14 Oct 2008 17:18:44 -0700
- Cc: "zsh-users@xxxxxxxxxx" <zsh-users@xxxxxxxxxx>
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=bgaL38aC1/t/WHRQmNTgF780/9D7qwpbVdVoPPms7IjQq8MpZCfLjWZf/PZec8bCSESurYnVzdjLspfv4hWvBUqOnz6oKAVagNYinP02DZdFFlbKVVuUqR+r2zVzWxq//GqHkSyfVZ/8hzrDYeS1lB6MPp3nnrV6Yu3kBnaZU6E=;
- In-reply-to: <20081014212839.bb5ecbad.mu_kuh@xxxxxxxx>
- Mail-followup-to: denis <mu_kuh@xxxxxxxx>, "zsh-users@xxxxxxxxxx" <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20081014212839.bb5ecbad.mu_kuh@xxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author