From 2fb2726ff199c1968fb06575e1b1f8b82baf37ba Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 25 Jul 2021 13:17:26 -0700 Subject: [PATCH] Updated SC2113 (markdown) --- SC2113.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/SC2113.md b/SC2113.md index a6aa0ad..93a69ad 100644 --- a/SC2113.md +++ b/SC2113.md @@ -2,30 +2,31 @@ ### Problematic code: -In `sh`, - ```sh -function quit { - exit +#!/bin/sh +function hello { + echo "Hello World" } ``` ### Correct code: -1. add `()` to after the function name. _this code newly cause [[SC2113]]._ - ```sh -function quit() { - exit +#!/bin/sh +hello() { + echo "Hello World" } -#=> SC2112: 'function' keyword is non-standard. Delete it. -``` -2. remove `function` +### Rationale: -```sh -quit() { - exit -} -#=> No issues detected! -``` \ No newline at end of file +`function` is a non-standard keyword that can be used to declare functions in Bash and Ksh. + +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. + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file