mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2113 (markdown)
35
SC2113.md
35
SC2113.md
@@ -2,30 +2,31 @@
|
|||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
|
|
||||||
In `sh`,
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
function quit {
|
#!/bin/sh
|
||||||
exit
|
function hello {
|
||||||
|
echo "Hello World"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
1. add `()` to after the function name. _this code newly cause [[SC2113]]._
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
function quit() {
|
#!/bin/sh
|
||||||
exit
|
hello() {
|
||||||
|
echo "Hello World"
|
||||||
}
|
}
|
||||||
#=> SC2112: 'function' keyword is non-standard. Delete it.
|
|
||||||
```
|
|
||||||
|
|
||||||
2. remove `function`
|
### Rationale:
|
||||||
|
|
||||||
```sh
|
`function` is a non-standard keyword that can be used to declare functions in Bash and Ksh.
|
||||||
quit() {
|
|
||||||
exit
|
In POSIX `sh` and `dash`, a function is defined without a `function` keyword. Instead, the function name is followed by `()` as in the correct example.
|
||||||
}
|
|
||||||
#=> No issues detected!
|
### Exceptions:
|
||||||
```
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user