mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
emit useless space and fix indentations
16
SC2034.md
16
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:
|
||||
|
||||
```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"
|
||||
``
|
||||
```
|
Reference in New Issue
Block a user