If your shell is /bin/bash
(as the question initially indicated), with far fewer changes than you think you need, since bash supports C-style for
loops. A more compressed syntax is possible with some releases, but to be safe across parser versions, being generous with whitespace is well-advised:
for (( j = ( i - ( i % 9) ); j < ( ( i - ( i % 9 ) ) + 9 ); j++ )); do echo "$j"; done
With /bin/sh
, by contrast:
j=$(( i - ( i % 9 ) ))
while [ "$j" -lt "$(( ( i - ( i % 9 ) ) + 9 ))" ]; do
echo "$j"
j=$(( j + 1 ))
done
As for your original attempt, brace expansions happen very early in the parsing process -- before any variables' values have been evaluated; consequently, they can't be used with any numbers that aren't static.