Build todo.sh in three steps: add and list, then done, then usage and error statuses.
~40 min Advanced 3 checked steps
Build it on a real Linux machine
The guided lab boots Linux in your browser. Each step runs a check script on that machine, so it passes only when your files and output are right.
What you will build
Step 1: Add tasks and list them
Build a todo tool in one script, todo.sh, in /workspace. This step covers add and list. The file that stores tasks comes from the TODO_FILE environment variable, and it defaults to todo.txt. add TEXT... appends the words joined by single spaces as one line. list prints each task as N. TEXT, numbered from 1. When the file does not exist, list prints nothing and exits with status 0.
Test it with a temporary TODO_FILE, adding buy milk and call mom, and then listing the tasks.
Step 2: Remove a task with done
Add the done command to todo.sh. done N removes task number N from the file and prints removed: followed by the task text. Tasks are numbered as list shows them, so after task 1 is removed, the task that was number 2 becomes number 1.
Test it by adding two tasks, running done 1, and then listing the file.
Step 3: Report usage and bad task numbers
Finish todo.sh with its error behavior. A missing or unknown command prints usage: todo.sh add TEXT... | list | done N to standard error and exits with status 2. done with a value that is not a positive whole number is a usage error with status 2. done with a number that has no task prints no task N to standard error and exits with status 1.
Test each case: no arguments, the unknown command frob, done 9 when only two tasks exist, and done x. Also confirm that done 1 still works.
Files
todo.sh: the finished script.
walkthrough.sh: every step of the reference solution, in order.
How it is checked
Each step in the guided lab has a check script that runs on the lab machine after you finish. It passes only when the files and output it expects are there, so the lab cannot be completed by reading alone.
Reference files
Read these after you have tried the lab. They are the solutions the checks were verified against.