mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2258 (markdown)
39
SC2258.md
Normal file
39
SC2258.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
## The trailing comma is part of the value, not a separator. Delete or quote it.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
for f in foo, bar, baz
|
||||||
|
do
|
||||||
|
echo "$f"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
for f in foo bar baz
|
||||||
|
do
|
||||||
|
echo "$f"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```sh
|
||||||
|
for f in "foo," "bar," "baz,"
|
||||||
|
do
|
||||||
|
echo "$f"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found a `for` loop where the items appear to be separated by commas. These will be treated as literal commas. If the commas are part of the value, enclose them in quotes, or remove them.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user