[BUG] Bash associative array with hyphened key malformed.
caspertsui opened this issue · 1 comments
caspertsui commented
Hello,
This bug is serious if it's enabled "format on save" feature.
associative_array=(
[hyphened-key]=value
...
)
would be formatted as
associative_array=(
[hyphened - key]=value
...
)
for shell scripts which breaks 1 single key into 3.
Thanks and regards,
Alan
meleu commented
This is a known upstream bug caveat.
The shfmt README lists this as a caveat, and suggests:
When indexing Bash associative arrays, always use quotes.
demonstration:
# key surrounded with 'single quotes'
$ echo "array=(['hyphened-key']=value )" | shfmt
array=(['hyphened-key']=value)
# key with "double quotes"
$ echo 'array=(["hyphened-key"]=value )' | shfmt
array=(["hyphened-key"]=value)