Project: a terminal dashboard

The dashboard gathers a few facts about the phone and lays them out under clear headings. This set covers printing figures with printf, guarding a read that may not exist, and choosing a section that always works offline.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 Why does the battery section test that the capacity file is readable before reading it?
2 In the disk line, what does printf with three %s placeholders, fed $3, $2 and $5, do?
3 In the case statement, why does the empty pattern have a branch of its own, separate from the wildcard?
4 The last section prints the time zone and the current time rather than a weather line. Why?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Print the disk and local lines

This prints the disk section and the local section the way the dashboard builds them, so you can see the figures filled into their sentences. The disk line is trimmed from df, and the local lines come from date.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

echo "Disk"; df -h / | tail -n +2 | awk '{printf " %s used of %s (%s)\n", $3, $2, $5}'; echo "Local"; echo " timezone $(date +%Z)"; echo " now $(date '+%H:%M')"
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson