mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2175 (markdown)
22
SC2175.md
Normal file
22
SC2175.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
## Quote this invalid brace expansion since it should be passed literally to eval
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
eval echo {1..$n}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
eval "echo {1..$n}"
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Using `eval somecommand {1..$n}` depends both on bash silently failing to interpret the brace expansion, and on it passing failing brace expansions literally.
|
||||||
|
|
||||||
|
Rather than depending on these questionable features (which already behave differently in other shells), use the explicit, predictable way of passing values literally: quoting.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user