shelllings

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

12_arguments.sh (606B)


      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 output=$(sh exercises/12_arguments.sh ugly Jayce big tofu)
     14 first_line=$(sh exercises/12_arguments.sh ugly Jayce big tofu | head -n 1)
     15 correct_first_line="One day, ugly Jayce left a big tofu in his pocket."
     16 
     17 [ "$first_line" != "$correct_first_line" ] && failed
     18 [ "$(echo "$output" | grep 4)" != "The number of words you used were: 4" ] && failed
     19 [ "$(echo "$output" | grep "The words")" != "The words you used were: ugly Jayce big tofu" ] && failed
     20 
     21 printf "${GREEN}Passed${RESET}\n"