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

order of processing in brace expansion

Consider the following:

pts/11 10:37 208%setopt braceccl                cato:/export/home/cato/apoindex
pts/11 10:38 209%foo=b,c                        cato:/export/home/cato/apoindex
pts/11 10:38 210%echo a{$foo}d                  cato:/export/home/cato/apoindex
a,d abd acd
pts/11 10:38 211%echo a{b,c}d                   cato:/export/home/cato/apoindex
abd acd
pts/11 10:38 212%unsetopt braceccl              cato:/export/home/cato/apoindex
pts/11 10:38 213%echo a{$foo}d                  cato:/export/home/cato/apoindex

According to info:

  Expansion is done in the above specified order in five steps.  The
  first is "history expansion" which is only performed in interactive
  shells.  The next step is "alias expansion" which is done right before
  the command line is parsed.  They are followed by "process
  substitution", "parameter expansion", "command substitution",
  "arithmetic expansion", and "brace expansion" which are performed in
  one step in left-to-right fashion.  After these expansions, all
  unquoted occurrences of the characters `\', `'', and `"' are removed
  and the result is subjected to "filename expansion" followed by
  "filename generation".

Since brace expansion has syntactic markers at two points there is some
ambiguity about where it would fall in the left to right processing but it
seems that neither choice should cause the actual behavior seen.

If brace expansion is considered to occur at the opening brace then I would

%setopt braceccl
%echo a{$foo}d
a$d afd aod
%unsetopt braceccl
%echo a{$foo}d

in the above example since the brace expansion would occur before $foo was
parameter expanded. 

If brace expansion is considered to occur at the closing brace then I would

%echo a{$foo}d
abd acd

since parameter expansion would occur first.  (The setting of brace_ccl would
be unimportant in this case.)

What actually occurs seems to be that it is decided what kind of brace
expansion is needed at the opening brace but the brace expansion is actually
done (consistent with the decision of type made earlier) at the closing brace.

My personal preference would be for brace expansion to occur entirely at the
closing brace since that seems to me to be the most useful definition.
Perhaps others have a different view.

Can anyone shed any light on what I might be overlooking here?

/-\ |_ |_ /-\ |\|

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