Braces count only with fixed numbers. To count to a number in a variable, loop over $(seq "$n"):
text
learner@reef:~$ echo {1..3}
1 2 3
learner@reef:~$ n=3
learner@reef:~$ echo {1..$n}
{1..3} ← no range, only text
learner@reef:~$ seq "$n"
1 ← seq N: from 1 to N, one per line
2
3
learner@reef:~$ for i in $(seq "$n"); do echo "tray $i"; done
tray 1
tray 2
tray 3Each tray in the north shop's kitchen gets a label file in ~/labels, as many as you're told.
-
Write
~/labels.sh N. It counts from 1 to$1. On each turn, it printslabel-$i.txtandtouches that file in~/labels. -
Make it runnable with
chmod u+x ~/labels.sh, and run it:textlearner@reef:~$ ./labels.sh 3 label-1.txt label-2.txt label-3.txt -
Try
./labels.sh 12.
Objectives
./labels.sh 3makes three labels and prints their names.- It works for any number:
./labels.sh 12makes twelve.