$(( )) works out a sum and puts the answer in the line:
text
learner@reef:~$ trays=3
learner@reef:~$ echo "$(( trays * 12 )) buns"
36 buns ← no $ before a name inside
learner@reef:~$ echo "$(( 7 / 2 ))"
3 ← whole numbers only
learner@reef:~$ n=0
learner@reef:~$ n=$((n + 5))
learner@reef:~$ n=$((n + 5))
learner@reef:~$ echo "$n"
10 ← a counter: add, and save it back in nEach oven says how many loaves it baked. Write ~/loaves.sh, which adds up the numbers that you give it:
text
learner@reef:~$ ./loaves.sh 24 36 18
total: 78
learner@reef:~$ ./loaves.sh
total: 0- Write it with
nano ~/loaves.sh: start a counter at0, then add each number in"$@"to it. - Make it runnable with
chmod u+x ~/loaves.sh, then run./loaves.sh 24 36 18. - Try it with no numbers.
Objectives
- Add up the numbers that you give it.
- With no numbers, it writes
total: 0.