#!/bin/sh -u # look for an optional string in the 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. #------------------------------------------------------------ # 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 Assignment Label # Comment: This is a sample assignment label. # see http://teaching.idallen.com/assignment_standards.html #------------------------------------------------------------- # Set a standard shell search path and a 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.