mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2051 (markdown)
@@ -24,18 +24,25 @@ In Bash, brace expansion happens before variable expansion. This means that brac
|
||||
|
||||
For integers, use an arithmetic for loop instead. For zero-padded numbers or letters, use of eval may be warranted:
|
||||
|
||||
```bash
|
||||
from="a" to="m"
|
||||
for c in $(eval "echo {$from..$to}"); do echo "$c"; done
|
||||
```
|
||||
|
||||
or more carefully (if `from`/`to` could be user input, or if the brace expansion could have spaces):
|
||||
|
||||
```bash
|
||||
from="a" to="m"
|
||||
while IFS= read -d '' -r c
|
||||
do
|
||||
echo "Read $c"
|
||||
done < <(eval "printf '%s\0' $(printf "{%q..%q}.jpg" "$from" "$to")")
|
||||
|
||||
```
|
||||
|
||||
### Exceptions
|
||||
|
||||
None (if you're writing for e.g. zsh, make sure the shebang indicates this so shellcheck won't warn)
|
||||
|
||||
### Related Resources:
|
||||
|
||||
* [StackOverflow: Variables in bash seq replacement ({1..10})](https://stackoverflow.com/questions/169511/how-do-i-iterate-over-a-range-of-numbers-defined-by-variables-in-bash)
|
Reference in New Issue
Block a user