for walks through a list. while TEST goes on as long as its test is true. It checks the test before every
turn, the first one too:
text
learner@reef:~$ cat late-price.sh
#!/bin/bash
# Usage: late-price.sh PRICE
price="$1"
while [ "$price" -ge 100 ]; do
echo "now $price cents"
price=$(( price / 2 )) ← change the test's variable, or the loop never ends
done
learner@reef:~$ ./late-price.sh 800
now 800 cents
now 400 cents
now 200 cents
now 100 cents ← next is 50: the test is false, the loop ends
learner@reef:~$ ./late-price.sh 60
learner@reef:~$ ← 60 is less than 100 at once: no turn at allThe oven needs a timer that counts down the minutes.
-
Write
~/oven-timer.sh N. It prints the numbers fromNdown to 1, thenready. -
Make it runnable with
chmod u+x ~/oven-timer.sh, and run it:textlearner@reef:~$ ./oven-timer.sh 3 3 2 1 ready -
Try
./oven-timer.sh 5, then./oven-timer.sh 0.
Objectives
./oven-timer.sh 3prints3,2,1, thenready.- It counts down from any number.
./oven-timer.sh 0prints onlyready.