#!/bin/sh
do_it ( )
{
# change delimiter to ':' instead of whitespace, then change it back
# input can be file:
# Jack Kenny:jkenny
OLDIFS=$IFS
IFS=:
while read name login; do
echo "name: $name login: $login"
/usr/sbin/useradd -g 100 -d /home/$login -c "$name" \
-m -k /etc/skel -s /bin/tcsh -o $login
done
# change the delimiter back to whitespace
IFS=$OLDIFS
}
# if the number of arguments is equal to zero print usage message
if [ $# -eq 0 ]; then
if [ -t 0 ]; then
echo "FATAL: Reading data from STDIN." >&2
echo " Must either do % $0 < datafile" >&2
echo " or % $0 \"Joe Cool\":login" >&2
echo "The datafile is expected to have one name and one login per line, separated by a colon." >&2
exit 2
fi
# else life is good print the arguments and call the subroutine
else
echo $*
fi | do_it