From c964c404d97609a828c2bfccc17e5ffa14f8c32d Mon Sep 17 00:00:00 2001 From: haruna Date: Sun, 26 Sep 2021 02:13:33 +0900 Subject: [PATCH] emit useless space and fix indentations --- SC2034.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/SC2034.md b/SC2034.md index ce8b777..d7a57b3 100644 --- a/SC2034.md +++ b/SC2034.md @@ -1,39 +1,41 @@ # foo appears unused. Verify it or export it. -### Problematic code: +## Problematic code: ```sh foo=42 echo "$FOO" ``` -### Correct code: +## Correct code: ```sh foo=42 echo "$foo" ``` -### Rationale: +## Rationale: Variables not used for anything are often associated with bugs, so ShellCheck warns about them. Also note that something like `local let foo=42` does not make a `let` statement local -- it instead declares an additional local variable named `let`. -### Exceptions +## Exceptions This warning may be falsely emitted when a variable is only referenced indirectly, and for variables that are intentionally unused. -#### Indirection +### Indirection It's ShellCheck's intended behavior to emit this warning for any variable that is only referenced though indirection: - # foo generates a warning, even though it has five indirect references - foo=42 - name=foo - echo "${!name} $((name))" - export "$name"; eval "echo $name" - declare -n name; echo "$name" +```sh +# foo generates a warning, even though it has five indirect references +foo=42 +name=foo +echo "${!name} $((name))" +export "$name"; eval "echo $name" +declare -n name; echo "$name" +``` This is an intentional design decision and not a bug. If you have variables that will not have direct references, consider using an associative array in bash, or just [[Ignore]] the warning. @@ -55,7 +57,7 @@ echo "$last, $zip" Or optionally as a prefix for dummy variables (ShellCheck >0.7.2). -``` ​ +```sh ​ read _first last _email zip _lat _lng <<< "$str" echo "$last, $zip" ``` @@ -66,4 +68,4 @@ For versions <= 0.7.2, the message can optionally be [[ignore]]d with a directiv # shellcheck disable=SC2034 # Unused variables left for readability read first last email zip lat lng <<< "$str" echo "$last, $zip" -`` \ No newline at end of file +``` \ No newline at end of file