#!/bin/sh -u # $0 (no arguments) # Prompt for a name, echo the name and a wakeup message, # then write that wakeup message to that person. # -IAN! idallen@ncf.ca June 2001 # # You need to edit this script to change the dummy names to be valid names # of people you know on the local computer. # # WARNING: Many of the comments in this file are "Instructor-Type" # comments and are *not* appropriate for real scripts. Do not put # "Instructor-Type" comments into the scripts that you submit for marking. # I put them in my example files because I am teaching you how to # write scripts; do not submit my teaching comments back to me again. # Read the week7.txt notes for more details on good comment style. export PATH=/bin:/usr/bin umask 022 # We loop until the user types one of the many "quit" keywords: # This should be a do/while loop; but, sh doesn't have one. # leave=no while [ "$leave" = "no" ] ; do # Get some input from stdin and echo it back to the user. # (It's always a good idea to echo back what the user enters, # just so the user sees what s/he really typed in!) # We always prompt a user for input on stderr, not on stdout. # The "tr" deletes the newline from the end of the echo output. # The echo of the input itself can safely go on stdout. # echo 1>&2 " " echo 1>&2 "Enter the name: " | tr -d '\012' read input echo "You entered: $input" # Select the words to write and the recipient based on the input. # Note how we always quote our variables to prevent glob expansion! # userid="" # start with empty userid case "$input" in me) words="Wakie Wakie!" userid="$USER" ;; a|alex) words="Yooo Hoooo!" userid=aaaa1111 # CHANGE THIS USERID ;; b|bobby) words="Wake Up!" userid=bbbb2222 # CHANGE THIS USERID ;; c|chris) words="Think Fast!" userid=cccc3333 # CHANGE THIS USERID ;; q|quit|x|exit|bye|leave|aurevoir|schus|salut|dosvedanja) echo " " echo "Quitting the script - bye now!" leave=yes ;; *) # Note how we say "unrecognized" instead of "illegal" # or "invalid" - the intent is to convey to the user # that our program wasn't smart enough to figure out # what the user typed, not that the user is an idiot! # Error messages such as these go to stderr, not stdout. # echo 1>&2 "$0: Unrecognized input \"$input\"" echo 1>&2 "Please enter a recognized name." echo 1>&2 "Valid names are: me alex bobby chris" ;; esac # If we entered a recognized name, $userid is set. # Echo the words and userid, then write the message. # Check for a good return status from the write operation. # if [ "$userid" ] ; then echo "Writing \"$words\" to \"$input\" (userid $userid)." if banner "$words" | write "$userid" ; then echo "Message written to $userid." else # We have to save the status to output it. # Error messages such as these go to stderr, not stdout. # status=$? echo 1>&2 " " echo 1>&2 "Error $status ocurred writing to $userid." fi fi done # Exit this script with a good return status. # exit 0