#!/bin/bash #### Add new records to file "p" #### if [ "$1" = "" ] || [ "$2" = "" ] then echo USAGE: echo " addname First Middle Last" echo " addname First Last" fi ## Check args if test $# -gt 3 then echo "ERROR: too many arguments (2 or 3 only)"; exit fi # if test $1 = "" || test -z $2 then echo "ERROR: addname requires two or three arguments."; exit fi ## Extract the name. first=$1 if test "$3" = "" then middle="" # No middle name last=$2 else middle="$2" last=$3 fi name="$first:$middle:$last" ## Now, get the phone number. echo "What is the phone number?" read phone if test $phone = 0 then echo "ERROR: Phone number cannot be zero!"; exit fi ## Assign an ID number. touch p let number=`wc -l p` echo number = $number let id=$number+1 echo id = $id ## +++++ job, birthdate ## ++++ Check for dups? ## Construct the record. record="$phone:$name:$id:$job:$birth" echo $record echo $record >> p # Append to file echo `wc -l p` records on file.