I'm writing a BASH script that asks a user for the number of columns and the number of items to put in the columns. The script will then put the numbers in the columns using for loops.
# Number of columns
cols=$1
# Number of items
num=$2
# Iterator variable
count=1
# Number of rows
rows=$(( ($num + ($cols - 1)) / $cols ))
for x in $(seq 1 1 $rows)
do
for y in $(seq 1 1 $cols)
do
echo -ne "$count\t"
(( count++ ))
done
echo ""
done
For example, if I enter 6 columns with 28 items this is what the output should look like.
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28
However, this is the output I get with the current code.
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
Thanks in advance for everyone's help!