-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC2111
Joachim Ansorg edited this page Oct 31, 2022
·
2 revisions
#!/bin/ksh
function foo() {
echo "Hello World"
}# POSIX sh function
foo() {
echo "Hello World"
}or
# ksh extended function
function foo {
echo "Hello World"
}Ksh allows two ways of defining functions: POSIX sh style foo() { ..; } and Ksh specific function foo { ..; }.
ShellCheck found a function definition that uses both at the same time, function foo() { ..; } which is not allowed. Use one or the other.
Note that the two are not identical, for example:
- Using
typesetin afunction foowill create a local variable, while infoo()it will create a global variable. -
function foohas its own trap context, whilefoo()shares them with the current process. -
function foowill set$0to foo, whilefoo()will inherit$0from the current process.
In Bash, function foo() { ..; } is allowed, and function foo and foo() are identical. This warning does not trigger when the shebang is e.g. #!/bin/bash.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!