mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created Sc2004 (markdown)
15
Sc2004.md
Normal file
15
Sc2004.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Don't use $ on variables in (( )).
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
echo $(($n+1))
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
echo $((n+1))
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
The `$` on regular variables in arithmetic contexts has no purpose, and is just noise.
|
||||||
|
|
||||||
|
The `$` does matter for special variables like `$1` vs `1`, `$#` vs `#`, and ShellCheck does not produce this style suggestion for these cases.
|
Reference in New Issue
Block a user