* Escaping shell characters in a string
@ 2003-09-09 16:52 Steve Talley
2003-09-09 17:06 ` Bart Schaefer
2003-09-09 17:08 ` Michał Politowski
0 siblings, 2 replies; 4+ messages in thread
From: Steve Talley @ 2003-09-09 16:52 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 668 bytes --]
If I set $fred:
% fred="a [ a * a ? a \ a"
If I expand fred while still on the command line:
% echo "$fred"<Tab>
Then all the shell space/glob characters are escaped:
% echo a\ \[\ a\ \*\ a\ \?\ a\ \\\ a
How can I get this quoting/escaping behavior within a zsh function?
That is, given a variable, how can I best escape all of the special
shell characters within? Is there a variable modifier I can use that
automatically escapes all special characters?
The best I've been able to come up with is:
escaped="$fred"
escaped="${escaped// /\\ }"
escaped="${escaped//\[/\\[}"
escaped="${escaped//\*/\\*}"
...
I know there has to be a better way.
Thanks,
Steve
[-- Attachment #2: Type: application/pgp-signature, Size: 185 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Escaping shell characters in a string
2003-09-09 16:52 Escaping shell characters in a string Steve Talley
@ 2003-09-09 17:06 ` Bart Schaefer
2003-09-09 17:14 ` Steve Talley
2003-09-09 17:08 ` Michał Politowski
1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2003-09-09 17:06 UTC (permalink / raw)
To: Zsh Users
On Sep 9, 12:52pm, Steve Talley wrote:
}
} How can I get this quoting/escaping behavior within a zsh function?
escaped=${(q)fred}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Escaping shell characters in a string
2003-09-09 16:52 Escaping shell characters in a string Steve Talley
2003-09-09 17:06 ` Bart Schaefer
@ 2003-09-09 17:08 ` Michał Politowski
1 sibling, 0 replies; 4+ messages in thread
From: Michał Politowski @ 2003-09-09 17:08 UTC (permalink / raw)
To: Zsh Users
On Tue, 9 Sep 2003 12:52:02 -0400, Steve Talley wrote:
[...]
> % fred="a [ a * a ? a \ a"
[...]
> That is, given a variable, how can I best escape all of the special
> shell characters within? Is there a variable modifier I can use that
> automatically escapes all special characters?
I believe ${(q)fred} is what you want.
--
Michał Politowski -- mpol@charybda.icm.edu.pl
Talking has been known to lead to communication if practised carelessly.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Escaping shell characters in a string
2003-09-09 17:06 ` Bart Schaefer
@ 2003-09-09 17:14 ` Steve Talley
0 siblings, 0 replies; 4+ messages in thread
From: Steve Talley @ 2003-09-09 17:14 UTC (permalink / raw)
To: Zsh Users
[-- Attachment #1: Type: text/plain, Size: 249 bytes --]
Thanks Bart/Micha! I thought I had RTFM thoroughly, but apparently
not. :^)
Steve
Bart Schaefer wrote:
> On Sep 9, 12:52pm, Steve Talley wrote:
>
> > How can I get this quoting/escaping behavior within a zsh
> > function?
>
> escaped=${(q)fred}
[-- Attachment #2: Type: application/pgp-signature, Size: 185 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-09-09 17:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-09 16:52 Escaping shell characters in a string Steve Talley
2003-09-09 17:06 ` Bart Schaefer
2003-09-09 17:14 ` Steve Talley
2003-09-09 17:08 ` Michał Politowski
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).