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

Re: how to get verbatim output in command substitution

On Tue, Mar 25, 2008 at 10:06:56AM -0700, Bart Schaefer wrote:
> On Mar 25,  3:01pm, Stephane Chazelas wrote:
> }
> } in list contexts, command substitution is split according to the
> } $IFS special parameter.
> That's not quite correct.  Zsh doesn't really have a concept of
> "list context" the way (say) Perl does.  For practical purposes it
> has what might be called "assignment context", and everything else.
> If scalar assignment syntax is used, then splitting is not done and
> the resulting variable becomes scalar (even if previously declared
> as an array); otherwise splitting is done (subject to the rules of
> parameter expansion and globbing as controlled by various options).

Well, what I call "list context" (I agree it's not an official
zsh term, I kind of made it up) is anywhere expecting several
words. That can be for i in <here>, var=(<here>), cmd <here>...

Non-list contexts are for instance scalar=<here>, case <here>
in, ${var#<here>}, "<here>", $((<here>)) and so on. In those,
there's no word splitting, as of course it wouldn't make sense.

So instead of "list context", you may call it "anywhere where it
would make sense to split" if you prefer, but you get the idea...

> That's separate from the behavior of trimming trailing whitespace
> from $(...).

Yes. Though it's not whitespace, it's only NL characters (all
the NL characters even though it would have made more sense to
remove only the last one, but that's Bourne's mistake, not


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