#! /bin/sh -e fail () { echo "ERROR: $*" 1>&2 exit 1 } case $1:$2:$3 in inventory::) cat <<EOT { "Puzzles": [1, 2, 3, 4, 5] } EOT ;; puzzle:1:) cat <<EOT { "Answers": ["answer1.0"], "Authors": ["author1.0"], "Body": "<h1>moo.</h1>" } EOT ;; puzzle:*) fail "No such puzzle: $2" ;; file:1:moo.txt) echo "Moo." ;; file:*:*) cat "$3" || exit 1 ;; answer:1:answer1.0) echo -n '{"Correct":true}' ;; answer:1:*) echo '{"Correct":false}' ;; answer:*:*) fail "Fail answer" ;; *) fail "What is $1" 1>&2 ;; esac