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
Ah, found the part of man zshall which explains this:
One final note, not directly related to subscripting: the numeric names of positional parameters (described below) are parsed specially, so for example $2foo is equivalent to ${2}foo. Therefore, to use subscript syntax to extract a substring from a positional parameter, the expansion must be surrounded by braces; for example, ${2[3,5]} evaluates to the third through fifth characters of the second positional parameter, but $2[3,5] is the entire second parameter concatenated with the filename generation pattern [3,5].
I agree that ${1}x is safer than $1x, but when I look for robustness and readability, I don't program in shell! 😏
Thanks for the fix and for shfmt in general. I had been waiting eagerly for zsh support. Now, all I need is zsh support in shellcheck!
Activity
mvdan commentedon Mar 14, 2026
Thanks, this appears to be a bug, also with a confusing error message.
It's worth noting that what you have here is rather fragile, i.e. zsh only allows it with numeric parameters, but any other parameter breaks.
mvdan commentedon Mar 14, 2026
What I mean by that is that something like
"^${1}[[:space:]]"is much less error-prone. But I'll try to fix the bug regardless.mvdan commentedon Mar 14, 2026
Ah, found the part of
man zshallwhich explains this:syntax: $1[foo] does not parse as a zsh subscript
charpov commentedon Mar 21, 2026
I agree that
${1}xis safer than$1x, but when I look for robustness and readability, I don't program in shell! 😏Thanks for the fix and for
shfmtin general. I had been waiting eagerly forzshsupport. Now, all I need iszshsupport inshellcheck!fix(deps): update module mvdan.cc/sh/v3 to v3.13.1 (#397)
chore(deps): update module mvdan.cc/sh/v3/cmd/shfmt to v3.13.1 (hetzn…