#!/bin/sh -u # This script compares two strings: an argument and stdin. #------------------------------------------------------------ # Syntax: # $0 string #------------------------------------------------------------ # Purpose: # Exit non-zero if there is not exactly one command line argument. # 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. #------------------------------------------------------------- # -IAN! idallen@idallen.ca # Use standard search path, friendly umask, ASCII collating and sorting. # Set the language and character set to be ASCII/C standard. # PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE LANG=C ; export LANG 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.