You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
syntax: errors and/or breaks code when arrays have keys that contain pound signs or variables #1285
The following is valid Bash, and when used in the context of a larger script (like this), it works as expected:
#!/usr/bin/env bash# ...for((I=0; I < ARGS[COMMAND,#]; I++));do
ENTR_ARGS+=("${ARGS[COMMAND,$I]}")
done
In the above code, the ARGS array has a key named COMMAND,# and also keys named COMMAND,1, COMMAND,2, etc. It might look a little unusual, but the code is valid, and that pattern is used by docopts.
When shfmt is run on that code, the following error occurs:
ef:4:28: , must be followed by an expression
If that issue is fixed, by quoting the name of the key, like this:
#!/usr/bin/env bash# ...for((I=0; I < ARGS['COMMAND,#']; I++));do
ENTR_ARGS+=("${ARGS[COMMAND,$I]}")
done
...and shfmt is run on the file again, then the code is formatted to the following, which does not work:
In the second-to-last line, the line beginning with ENTR_ARGS+=, notice that a space was inserted after the comma and the dollar sign was removed from the I variable.
As before, the workaround appears to be quoting the name of the key. The nested double quotes look weird, but it works as expected, so I assume it's valid Bash:
#!/usr/bin/env bash# ...for((I =0; I < ARGS['COMMAND,#']; I++));do
ENTR_ARGS+=("${ARGS["COMMAND,$I"]}")
done
changed the title [-]shfmt errors and/or breaks code when arrays have keys that contain pound signs or variables[/-][+]syntax: errors and/or breaks code when arrays have keys that contain pound signs or variables[/+]on Mar 15, 2026
Activity
[-]shfmt errors and/or breaks code when arrays have keys that contain pound signs or variables[/-][+]syntax: errors and/or breaks code when arrays have keys that contain pound signs or variables[/+]syntax: add test cases for issue #1285
syntax: allow pound signs in associative array keys
interp: bridge address-backed unsafe pointers to native parameters