back to labs
Exit Codes: A Validator Other Scripts Can Branch On
MediumShell Scripting15-25 minThe brief
Write a small validator at /usr/local/bin/check-cfg that takes one argument — a config file path — and returns a distinct exit status per condition, so a calling script can branch on it:
- called with no argument → print a usage message to stderr,
exitwith the usage code - argument names a missing file →
exitwith the missing-file code - argument names an existing file →
exit 0
The exact codes are in /root/case/brief.txt (they vary per session — read them). Grading runs your script for each case and checks $?. Make it executable.
What you'll do
- Handle argument count with $# and read $1
- Return distinct, meaningful exit codes per condition
- Write a script whose status a caller can branch on
Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.
