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

When is a pre-command assignment syntactically valid?



In z-sy-h we're trying to determine in what circumstances an assignment is
valid before a command.¹

Empirically, when an assignment is followed by one of the reserved words
  «((» «[[» «(» «{» «!»
a parse error results, but when an assignment is followed by the name of a
command, builtin, or function, execution succeeds.  It doesn't seem to matter
whether the assigned parameter is a scalar or an array.  (Of course, setting
an array in front of an external command, as in «a=(foo bar) /bin/true», isn't
necessarily _useful_ — barring 'typeset -T' and hooks — but it's syntactically
valid, which is z-sy-h's concern.)

So, I think the rule is: "reserved words may not be preceded by parameter
assignments".  Is that accurate?

Thanks,

Daniel

P.S. Incidentally, I can see how it might be useful to allow assignments before
some of these constructs (e.g., «foo=bar (subshell; commands;)»), but I'm not
advocating for that; I'm just trying to grok the status quo so z-sy-h can
support it.

¹ https://github.com/zsh-users/zsh-syntax-highlighting/issues/461



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