#!/bin/sh -u # This script compares two strings: an argument and stdin. #------------------------------------------------------------ # Syntax: # $0 string #------------------------------------------------------------ # Purpose: # Prompt for and read a string. Compare it with the single command # line argument and print whether or not it matches. Exit zero # only if the strings match. Exit non-zero otherwise. #------------------------------------------------------------- # Student Name: Ian! D. Allen # Algonquin EMail Address: alleni # Student Number: 000-000-000 # Course Number: DAT2330 # Lab Section Number: 010 # Professor Name: Ian! D. Allen # Assignment Name/Number/Date: Sample Assignemnt Label # Comment: This is a sample assignment label. # see http://teaching.idallen.com/assignment_standards.html #------------------------------------------------------------- # Set standard search path and umask. # PATH=/bin:/usr/bin ; export PATH umask 022 # Make sure we have exactly one command line argument. # If not, echo the count and incorrect input back to the user on stderr. # if [ $# -ne 1 ] ; then echo 1>&2 "$0: Expecting one argument, found $# ($*)" exit 1 fi # Echo the user's input argument back to the user before using it. # echo "Argument string is: '$1'" # Warn the user of the argument string is empty (no characters). # if [ -z "$1" ] ; then echo 1>&2 "$0: Warning: your argument string is empty (no characters)" fi # Prompt for input (always on stderr) and read another string. # Echo the user's input back to the user before using it. # echo 1>&2 "Enter one line of input:" read string echo "Input string is: '$string'" # Warn the user of the string read in is empty (no characters). # if [ -z "$string" ] ; then echo 1>&2 "$0: Warning: your input string is empty (no characters)" fi # Compare the two strings and exit non-zero if they differ. # if [ "$1" != "$string" ] ; then echo "Argument string '$1' does not match input string '$string'." exit 1 fi echo "The two strings match each other: '$1'" # The script exits with exit status of last command executed.