mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1065 (markdown)
26
SC1065.md
Normal file
26
SC1065.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
## Trying to declare parameters? Don't. Use () and refer to params as $1, $2..
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
foo(input) {
|
||||||
|
echo "$input"
|
||||||
|
}
|
||||||
|
foo("hello world");
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
foo() {
|
||||||
|
echo "$1"
|
||||||
|
}
|
||||||
|
foo "hello world"
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Shell script functions behave just like scripts and other commands:
|
||||||
|
|
||||||
|
- They always take a 0 to N parameters, referred to with `$1`, `$2` etc. They can not declare parameters by name.
|
||||||
|
- They are executed using `name arg1 arg2`, and not with parentheses as C-like languages.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user