Updated SC2051 (markdown)

koalaman
2018-01-25 19:29:07 -08:00
parent d0ef7a4c3c
commit d7a155e77d

@@ -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)