Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: quote modifier for parameter expansion?
- X-seq: zsh-workers 5210
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: quote modifier for parameter expansion?
- Date: Wed, 3 Feb 1999 17:28:18 +0100 (MET)
- In-reply-to: Peter Stephenson's message of Wed, 03 Feb 1999 17:02:18 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Peter Stephenson wrote:
> Sven Wischnowsky wrote:
> > Hm. I'm sure I'm missing something again, but could anyone please tell
> > me what? The patch below (which probably shouldn't be used) just uses
> > the quote()-function from hist.c to make the `q' modifier in parameter
> > expansion work. The result is almost always a funny looking string in
> > single quotes, but that alone can't be the reason not to use this
> > function.
>
> Does exactly what I would expect it to.
>
> % bar="hello'there"
> % print -r $bar:q
> 'hello'\''there'
>
> Maybe the point is simply it's got limited application, since unless
> it's going into an eval the extra quotes aren't all that useful,
> unlike in history substitution which happens before the quotes get
> swallowed.
But it's also useful if you stuff a string together in a parameter and
later use the value of that parameter for globbing. With `:q' you can
prevent pattern characters in the original parameters from being
interpreted as a pattern.
That's what makes it useful in functions like pfiles(). Without the
patch below and using:
zle -C my-comp complete-word main-complete
doing `foo *<TAB>' will give one all files as possible completions.
Of course, this is the same use as with eval (i.e. double evaluation).
Bye
Sven
--- om/new-completion-examples Wed Feb 3 16:16:57 1999
+++ Misc/new-completion-examples Wed Feb 3 17:25:29 1999
@@ -211,7 +211,7 @@
ppres=( '' )
fi
- str="$PREFIX*$SUFFIX"
+ str="${PREFIX:q}*${SUFFIX:q}"
if [[ -z "$a[1]" || "$str[1]" = [~/] || "$str" = (.|..)/* ]] then
a=()
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author