#!/bin/sh -u # Week 8 lab script - look for an optional string in Unix password file # Syntax: $0 [ string ] # Purpose: # Take one optional argument and look for it in the password file. If the # argument is missing, prompt for it and read it. Exit non-zero if there # are not 0 or 1 arguments or if the string is empty. # set standard search path and friendly umask # PATH=/bin:/usr/bin ; export PATH umask 022 #echo "DEBUG the count of arguments is $#" # Make sure we have 0 or 1 arguments; exit non-zero if more than 1. # if test "$#" -gt 1 ; then echo 1>&2 "$0: Number of arguments $# is greater than 1: ($*)" exit 1 fi # Prompt on stderr and read string from standard input if no argument. # If a command line argument is present, use it as the string. # if test $# -eq 0 ; then echo 1>&2 "Enter a string to search for:" read string else string="$1" fi #echo "DEBUG the string is $string" # Make sure string is not empty; exit non-zero if it is empty. # if test "$string" = "" ; then echo 1>&2 "$0: empty string not accepted - nothing done" exit 2 fi # Look for the string in the Unix password file. # grep "$string" /etc/passwd # Scripts exit with the return code of the last command executed.