Use function_name()
and refer to passed parameters as $1
, $2
etc.
Shell script functions behave just like scripts and other commands:
- They always take 0 to N parameters, referred to by $1
, $2
etc. They cannot declare parameters by name.
- They are executed using name arg1 arg2
, and not with parentheses as C-like languages.
foo(input) {
echo "$input"
}
foo("hello world");
foo() {
echo "$1"
}
foo "hello world"