forked from koalaman/shellcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
SC2051
Peter Urda edited this page Dec 23, 2015
·
7 revisions
for i in {1..$n}
do
echo "$i"
done
for ((i=0; i<n; i++))
do
echo "$i"
done
In Bash, brace expansion happens before variable expansion. This means that brace expansion will not account for variables.
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):
from="a" to="m"
while IFS= read -d '' -r c
do
echo "Read
None (if you're writing for e.g. zsh, make sure the shebang indicates this so shellcheck won't warn)