From b58da32b0506f5db8df488425a132b6a64ed0ea3 Mon Sep 17 00:00:00 2001 From: koalaman Date: Fri, 5 Jun 2015 12:34:05 -0700 Subject: [PATCH] Created SC1065 (markdown) --- SC1065.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SC1065.md diff --git a/SC1065.md b/SC1065.md new file mode 100644 index 0000000..e7be955 --- /dev/null +++ b/SC1065.md @@ -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. \ No newline at end of file