Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 622 Bytes

SC1065.md

File metadata and controls

32 lines (22 loc) · 622 Bytes

Pattern: Declaring parameters in shell script

Issue: -

Description

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.

Example of incorrect code:

foo(input) {
  echo "$input"
}
foo("hello world");

Example of correct code:

foo() {
  echo "$1"
}
foo "hello world"

Further Reading