Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Force globbing inside of parameter substitution



On Jun 1,  4:11pm, Andrej Borsenkow wrote:
} Subject: Force globbing inside of parameter substitution
}
} Suppose, I need a list of files sperated by comma.

	"${(j/,/)${(f)$(print -rl -- *)}}"

You probably don't need the `-r' or the `--', but I'm paranoid.

} ${(j/,/)${:-*}}
} 
} Unfortunately, it does not work - it simply results in single `*'.

Yes ... filename generation always happens after parameter expansion.

} As a side note: it looks, like GLOB_SUBST does not apply in the above case.
} I have globsubst off, but the result of ${:-*} is still globbed. Is it
} intentional? I would deem it as a bug.

The stuff on the RHS of :- (and :+ etc.) is treated as if it were outside
the ${ } for purposes of tokenization.  That's why POSIX permits quotes
to appear inside the braces: so you can do stuff like ${1+"$@"}.  I should
have remembered that when I brought up quoting yesterday.

Interestingly, ${(e):-*} produces an untokenized * (which is not globbed).
I'd be more inclined to call _that_ a bug.

} Using ${(j/,/)$(print *)} does _almost_ wat I'd like ... with two caveats:
} 
} 1. the file names with spaces are mangled

Quoting and print -rl should deal with that.  You don't have any file
names with newlines, do you?

} 2. it is potentially less efficient.

Yes.

} Is the use of temporary array the only possibility?

The only way to avoid a $(...), yes.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author