#!/bin/sh # this demonstrates the if-then construct # as well as demonstrating the read and test builtins #notice that I use double quotes around the $word variable #that way if a user running the program enters 2 words, they work #the -n after the echo tells the shell not to output a newline after echo "This is a game to see if you can enter 2 words and" echo " the program will tell you if they were a match" echo -n "Please enter word 1: " read word1 echo ; echo ; echo echo -n "Please enter word 2: " read word2 #notice that the test builtin (p. 371) has 3 arguments #there is a more traditional test see p. 374 the spaces are important if test "$word1" = "$word2" then echo "The words that you entered were a Match" else echo "Sorry try again" exit 10 fi echo $? was the exit status of the ifthen echo echo echo "this program is done, please try again if you like" #CSC128: Shell Script Examples - if-then-else and exit example