shelllings

a practical way to learn shell
Log | Files | Refs | README | LICENSE

18_quiz.sh (584B)


      1 #!/bin/sh
      2 
      3 set -eu
      4 RED="\033[31m"
      5 GREEN="\033[32m"
      6 RESET="\033[0m"
      7 
      8 failed() {
      9 	printf "${RED}Failed${RESET}\n"
     10 	exit 1
     11 }
     12 
     13 cleanup() {
     14 	[ -f "notes.txt" ] && rm notes.txt
     15 }
     16 trap cleanup EXIT
     17 
     18 sh exercises/18_quiz.sh get oreos for protein shake > /dev/null || failed
     19 sh exercises/18_quiz.sh -p this line should appear > /dev/null || failed
     20 sh exercises/18_quiz.sh -p > /dev/null || failed
     21 sh exercises/18_quiz.sh > /dev/null || failed
     22 
     23 [ ! $(grep "get oreos" notes.txt | wc -l) -eq 1 ] && failed
     24 [ ! $(grep "\-p" notes.txt | wc -l) -eq 1 ] && failed
     25 
     26 printf "${GREEN}Passed${RESET}\n"