I'm using shfmt 3.12.0.
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:
#!/usr/bin/env bash
# ...
for ((I = 0; I < ARGS['COMMAND,#']; I++)); do
ENTR_ARGS+=("${ARGS[COMMAND, I]}")
done
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
I'm using shfmt 3.12.0.
The following is valid Bash, and when used in the context of a larger script (like this), it works as expected:
In the above code, the
ARGSarray has a key namedCOMMAND,#and also keys namedCOMMAND,1,COMMAND,2, etc. It might look a little unusual, but the code is valid, and that pattern is used bydocopts.When
shfmtis run on that code, the following error occurs:If that issue is fixed, by quoting the name of the key, like this:
...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 theIvariable.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: