Signal9Signal9 — home
online
back to labs

Functions Two Ways: Return Data and Return Status

MediumShell Scripting15-25 min
The brief

A function is a command you define — and it hands results back over two different channels: data (it echos a value, the caller captures it with $( )) and status (its exit code answers yes/no, so it slots into an if). Build /root/scripts/report.sh from both.

Your per-session assignment is in /root/case/assignment.env (WORD, N). Define:

1. shout() — echoes its argument uppercased (data channel).

2. is_big() — a predicate that succeeds when its numeric argument is >= 10 (status channel).

Then print SHOUT=<WORD uppercased> and BIG=<yes/no> using those functions. Keep helper variables local. Grading runs the script and checks the output, then sources it and calls shout and is_big with arguments you haven't seen, so the functions must work on their argument rather than on this assignment's values. See /root/case/brief.txt for a skeleton.

What you'll do
  • Define a data-returning function (echo + $() capture)
  • Define a predicate function whose exit code is the answer
  • Use them to produce SHOUT and BIG from the assignment
  • Keep function-internal variables local

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.