I am trying to control (via multiple IF statements) the integer range of a defined variable within a while loop in Linux.
My Bash Code:
#!/bin/bash
pad=3
START=1
END=246
i=${START}
while [ ${i} -le ${END} ];
do
num=$(printf "%0*d\n" $pad ${i})
echo "${num}"
if [ ${num} -lt "36" ];
then
((i = i + 1))
fi
if [ ${num} -ge "36" ] && [ ${num} -le "192" ];
then
((i = i + 3))
fi
if [ ${num} -ge "192" ] && [ ${num} -le "246" ];
then
((i = i + 6))
fi
done
exit 0
Expected Output:
001
...
...
...
036
039
042
...
...
...
192
198
204
...
...
...
240
246
Terminal Output:
001
...
...
...
036
039
042
...
...
...
192
198
201
204
...
...
...
243
246
After the IF condition has been met, post-192 and pre-246, the ${num} variable is still increasing by 3 instead of increasing by 6.
printf '%s\n' {1..36} {39..192..3} {198..246..6}?