mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2112 (markdown)
34
SC2112.md
34
SC2112.md
@@ -1 +1,33 @@
|
|||||||
# 'function' keyword is non-standard. Delete it.
|
## 'function' keyword is non-standard. Delete it.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/sh
|
||||||
|
function hello() {
|
||||||
|
echo "Hello World"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/sh
|
||||||
|
hello() {
|
||||||
|
echo "Hello World"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
`function` is a non-standard keyword that can be used to declare functions in Bash and Ksh.
|
||||||
|
|
||||||
|
In POSIX `sh` and `dash`, a function is instead declared without the `function` keyword as in the correct example.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user