#!/bin/sh -u # Test to see if a string is in the online user list # # Syntax: $0 string # # This script looks for the given string in the list of online users # and prints a chatty message about whether or not it was found. # # This illustrates using the exit status of a command pipeline # in an IF statement. # # -IAN! idallen@idallen.ca # Set the standard search path and file umask for this script. # PATH=/bin:/usr/bin ; export PATH umask 022 # Make sure we have exactly one command line argument. # if [ $# -ne 1 ] ; then echo 1>&2 "$0: expecting one string argument, found $# ($*)" exit 1 fi # Copy the command line argument to give it a better name than "$1" # string="$1" echo "You are looking for string '$string' in the online user list" # We don't want the output of grep to appear on the screen; # we are only interested in the return status of grep in the pipeline. # if who | grep "$string" >/dev/null ; then echo "Found: '$string' in the online user list" else echo "NOT FOUND: '$string' in the online user list" fi