Step 6 of 7 · lab · 25 min
Fix the report script
The upload check script lets empty files through, cuts names apart and hides failures — bring it up to its contract.
Situation
Every night the branches send their uploads to ~/import/inbox, and the importer loads them
into the database. Before loading it runs a check and goes on only if the check returned 0:
bash report.sh inbox/*.csv && import-uploads inbox/*.csv
A colleague wrote ~/import/report.sh; the contract is written in the script's header. In the
morning you look at the output of the night's check: it has more lines than there are uploads,
the empty east.csv passed as OK, and the import started even though the output has a
FAIL in it.
Task
Fix ~/import/report.sh so that it keeps its contract:
- exactly one line on stdout per argument, in the same order:
OK <argument>orFAIL <argument>; the argument exactly as passed, even with a space or an asterisk*in the name; nothing on stderr meanwhile; OKonly if it is a regular file (or a link to one), it can be read and it is not empty; otherwiseFAIL;- exit status 1 if at least one file got
FAIL, wherever it stands, and 0 if all areOK; - without arguments — empty stdout, the line
Usage: report.sh FILE...on stderr and exit status 2.
The check runs the script as you — bash ~/import/report.sh … — on its own files, which are
not in inbox. The uploads in inbox are for your experiments: fix the script, not them.
Lab · on your own
No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.
Goals
0 of 4-
One line per argument with the name exactly as passed, even with a space or an asterisk; stderr is empty — not done yet
-
OK only for a regular non-empty file that can be read, or for a link to such a file — not done yet
-
Exit status 1 if any file fails, wherever it stands; exit status 0 if all pass — not done yet
-
Without arguments — empty stdout, a Usage line on stderr and exit status 2 — not done yet
The machine is starting
Hints
0 of 3Lab goals
0 of 4-
One line per argument with the name exactly as passed, even with a space or an asterisk; stderr is empty — not done yet
-
OK only for a regular non-empty file that can be read, or for a link to such a file — not done yet
-
Exit status 1 if any file fails, wherever it stands; exit status 0 if all pass — not done yet
-
Without arguments — empty stdout, a Usage line on stderr and exit status 2 — not done yet
Goals are checked on the machine after every command.