#!/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. #------------------------------------------------------------ # -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 #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.