Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Bash associative array with hyphened key malformed. #275

Open
caspertsui opened this issue Jan 3, 2022 · 1 comment
Open

[BUG] Bash associative array with hyphened key malformed. #275

caspertsui opened this issue Jan 3, 2022 · 1 comment
Labels
upstream the upstream problem

Comments

@caspertsui
Copy link

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
Copy link

meleu commented Mar 25, 2022

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)

@foxundermoon foxundermoon added the upstream the upstream problem label Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream the upstream problem
Projects
None yet
Development

No branches or pull requests

3 participants