I can define bash
functions using or omitting the function
keyword. Is there any difference?
#!/bin/bash
function foo() {
echo "foo"
}
bar() {
echo "bar"
}
foo
bar
Both calls to functions foo
and bar
succeed and I can't see any difference. So I am wondering if it is just to improve readability, or there is something that I am missing…
BTW in other shells like dash
(/bin/sh
is symlinked to dash
in debian/ubuntu) it fails when using the function
keyword.
Best Answer
There is no difference AFAIK, other than the fact that the second version is more portable.