Optional check: function declarations should not have `function` prefix
EDIT: I had initially proposed the opposite, but I changed my mind about this. See the conversation below.
This is to ensure a consistent code style. Example:
function myfunction() {
true
}
Should be:
myfunction() {
true
}
Original issue description
This was before I changed my mind.
This is to ensure a consistent code style. Example:
myfunction() {
true
}
Should be:
function myfunction() {
true
}
I came here to actually suggest the opposite of this.
according to This SO post; the use of:
function myfunction() { ... ; }
is completely wrong, and shouldn't be used; and that the expected syntax is:
myfunction(){ ...; }
I'm not confident in this, but would enjoy seeing the resulting conversation around correctness here ;)
This seems like a "try it and see" kind of question to me. :-)
~ $ bash --version GNU bash, version 5.3.0(1)-release (aarch64-unknown-linux-android) ~ $ function bla2 () { printf '<%s>\n' "$@";} ~ $ bla2 4 5 76 <4> <5> <76> ~ $ unset -f bla2 ~ $
Perhaps this 'function word ()...' syntax causes an error in some other shell?
On Wed, Jul 23, 2025, 22:24 Wolf Noble @.***> wrote:
wolfspyre left a comment (koalaman/shellcheck#2645) https://github.com/koalaman/shellcheck/issues/2645#issuecomment-3112001295
I came here to actually suggest the opposite of this.
according to This SO post https://stackoverflow.com/questions/22238033/should-i-define-a-shell-function-as-function-x-or-just-x; the use of:
function myfunction() { ... ; }
is completely wrong, and shouldn't be used; and that the expected syntax is:
myfunction(){ ...; }
I'm not confident in this, but would enjoy seeing the resulting conversation around correctness here ;)
— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/2645#issuecomment-3112001295, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUF2F25WNXNIPEU7LHEAA433KBUYTAVCNFSM6AAAAACCHXCMO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCMJSGAYDCMRZGU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
erm... no?
Just cause somethin works doesn't mean it's necessarily a good idea :)
according to the docs 'function' AND '()' aughtn't be used in conjunction. bash and zsh enable it, but it's not proper, strictly speakin.... will it work? sure. but if that's all one cared about, why would one use shellcheck in the first place? :)
Since we're talking about a tool which is intended to suggest patterns which reflect current best practices I'd hope that effaroundandfindout isn't the de-facto mechanism of evaluating the merit of a pattern...
:)
but I do admit this is kinda nit-picky...
I agree with you, @wolfspyre, f() { echo hello world; } should be the preferred one. I updated the issue description to make this clearer.
Also referenced in https://mywiki.wooledge.org/Bashism.
Well, there are some varying levels of "proper" under consideration.
Would 'function word ()...' conform to [pick your favorite corporation's] Style Guide? Maybe / maybe not. That's up to them.
Is said syntax a shell error, meaning, could such syntax cause, for instance
- a backup script to silently fail,
- data to be read or processed incorrectly,
- unexpected side effect(s) to occur, or
- for one to "incur the wrath from high atop the thing?"
Case in point:
In my opinion, if people claim some syntax is "wrong," it may be worthwhile to ask for whom and when.
On Thu, Jul 24, 2025, 11:09 Wolf Noble @.***> wrote:
wolfspyre left a comment (koalaman/shellcheck#2645) https://github.com/koalaman/shellcheck/issues/2645#issuecomment-3114383678
erm... no?
Just cause somethin works doesn't mean it's necessarily a good idea :)
according to the docs 'function' AND '()' aughtn't be used in conjunction. bash and zsh enable it, but it's not proper, strictly speakin.... will it work? sure. but if that's all one cared about, why would one use shellcheck in the first place? :)
Since we're talking about a tool which is intended to suggest patterns which reflect current best practices I'd hope that effaroundandfindout isn't the de-facto mechanism of evaluating the merit of a pattern...
:)
but I do admit this is kinda nit-picky...
— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/2645#issuecomment-3114383678, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUF2F22RQQ5IT4OK3LZIST33KEOMJAVCNFSM6AAAAACCHXCMO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTCMJUGM4DGNRXHA . You are receiving this because you commented.Message ID: @.***>
That's why this ask is for an optional check, like these:
- https://www.shellcheck.net/wiki/SC2250
- https://www.shellcheck.net/wiki/SC2248
- https://www.shellcheck.net/wiki/SC2292
I would like a optional check for this indeed. (on team "don't use the function keyword" =))