Nov 11, 2024
Shell functions don’t need parentheses
Copilot surprised me by generating a zsh function that looked like this:
function act {
# do stuff
}Instead of like this:
act() {
# do stuff
}It turns out function parentheses are optional in bash and zsh. Though, using parentheses is more POSIX compliant if that's relevant for your use case.
In fact, all of these variations are equivalent:
function act () {
command
}
function act() {
command
}
function act {
command
}
act () {
command
}
act() {
command
}
act () command
act() command