mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2051 (markdown)
14
SC2051.md
14
SC2051.md
@@ -18,7 +18,19 @@
|
|||||||
|
|
||||||
In Bash, brace expansion happens before variable expansion. This means that brace expansion will not account for variables.
|
In Bash, brace expansion happens before variable expansion. This means that brace expansion will not account for variables.
|
||||||
|
|
||||||
Use an arithmetic for loop instead.
|
For integers, use an arithmetic for loop instead. For zero-padded numbers or letters, use of eval may be warranted:
|
||||||
|
|
||||||
|
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 or globs):
|
||||||
|
|
||||||
|
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")")
|
||||||
|
|
||||||
|
|
||||||
### Contraindications
|
### Contraindications
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user