Closed andras-kth closed 2 years ago
Apparently, the "bug(?)" has to do with the "at" sign (@
), since using an equal sign (=
) instead works fine...
$ shfmt
=() {
echo "$@"
}
= Hello world\!
=() {
echo "$@"
}
= Hello world\!
$
Found a workaround (I just love the internet...):
$ shfmt
@()
{
echo "$@"
}
@ Hello world\!
@()
{
echo "$@"
}
@ Hello world\!
I'm still not sure why shfmt
treats @
special,
or why the added line-break makes it tick,
but this solves my issue for the time being...
Interestingly, it's not only the "at" sign (@
) that appears to be special but the plus sign (+
) as well:
$ for i in @ + - = , ^; do echo; echo __ $i __; echo "$i() { echo yay; }" | shfmt; echo; done
__ @ __
<standard input>:1:17: "}" can only be used to close a block
__ + __
<standard input>:1:17: "}" can only be used to close a block
__ - __
-() { echo yay; }
__ = __
=() { echo yay; }
__ , __
,() { echo yay; }
__ ^ __
^() { echo yay; }
Thanks for the report! This might be a bug in the parser. I'd be happy to review a patch if you're up for looking into it :)
Thanks for the report! This might be a bug in the parser. I'd be happy to review a patch if you're up for looking into it :)
Actually, I'm not. The only reason I use this tool is because I'm forced to. I'm fully capable of writing shell code in a format that I like, and I truly hate some of the formatting choices made for me...
One clear and present danger with tools like this is that they are often misused by local micro-dictators to force a straight-jacket of uniformity on their work force, in the name of maintainability.
I'm not sure how to answer to that, so I won't :)
I'll take a look at this @mvdan :)
Sounds good!
I'm struggling to understand what's wrong with this sample: