Closed Bushmills closed 1 month ago
We don't support arbitrary Bash syntax in some edge cases. Your case is quite similar to the one mentioned in the README:
Some builtins like
export
andlet
are parsed as keywords. This allows statically building their syntax tree, as opposed to keeping the arguments as a slice of words. It is also required to supportdeclare foo=(bar)
. Note that this means expansions likedeclare {a,b}=c
are not supported.
https://github.com/mvdan/sh/issues/583#issuecomment-652898693 is also a similar answer I gave to a similar request - expanding arithmetic operators is conceptually quite similar to expanding assignments. If we allow all the kinds of magic that Bash does, then our arithmetic expression parser would do little more than collecting unstructured words and leaving it to the interpreter to do the heavy lifting. Imagie expr="foo=bar baz"; (($expr))
as an example.
I could make the README clearer about this, however, as it currently seems like the restriction only applies to builtins, which is not the case.
It seems that shfmt won't deal with a bash technique which is used in this code fragment: