mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.98k stars 332 forks source link

shfmt considers export {foo,bar}= as an invalid variable #980

Closed mikeBashStuff closed 1 year ago

mikeBashStuff commented 1 year ago

The following example is a valid Bash code:

export {FOO,BAR}=
export {foo,bar}=this_is_valid

declare -p {FOO,BAR,foo,bar}

$ ./foo
declare -x FOO=""
declare -x BAR=""
declare -x foo="this_is_valid"
declare -x bar="this_is_valid"

However, shfmt (checked the latest v3.6.0 release as well) reports a following error:

# SHFMT_NO_EDITORCONFIG=true shfmt-3.6.0 -i 0 -bn -ci -ln bash -d -sr ./foo
./foo:1:8: invalid var name
#
mvdan commented 1 year ago

See https://github.com/mvdan/sh/issues/858#issuecomment-1155078373 and the last example under https://github.com/mvdan/sh#caveats. This is a known limitation. Closing as a duplicate of 858, because both are different examples of the same problem.