56/60
Sign inSign up free

750. Long Options by Hand

medium 20 XP ~12 minHands-on lab

getopts only knows short options. Write /home/student/bin/backup.sh that accepts:

backup.sh --source DIR --dest DIR [--compress] [--keep N] [--help]

Task

  • --source and --dest take a value, given either as --source DIR or --source=DIR. Both are required.
  • --keep N (also --keep=N) is a whole number, default 7.
  • --compress is a flag (no value).
  • On success, print exactly one line: source=<DIR> dest=<DIR> keep=<N> compress=<yes|no> and exit 0.
  • --help: print the usage line usage: backup.sh --source DIR --dest DIR [--compress] [--keep N] to stdout, exit 0.
  • An unknown option, a missing value, a missing required option or a --keep that isn't a whole number: print that usage line to stderr and exit 2.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.