After adding the -m option, add a -s option to specify that the mail message is only to be sent if there's one and only one match to the search query.
What will be an ideal response?
A half-dozen more lines added to the code block for #1. Here's one solution:
# if the user specifies -m addr then email the result of the lookup to
# the specified recipient
if [ "$1" = "-m" ] ; then
recipient="$2"
shift 2
if [ -z "$recipient" ] ; then
echo "Error: -m requires an email recipient address"
exit 1
fi
if [ "$1" = "-s" ] ; then # only email if a single match
matches="$(grep -i "$@" $PHONEBOOK | wc -l | sed 's/[^0-9]//g')"
if [ $matches -ne 1 ] ; then
echo "Error: $matches matches to your pattern. No mail sent."
exit 1
fi
shift
fi
$lu "$@" | mail -s "rolo output" $recipient
exit 0
fi
You might also like to view...
Appointments, events, and meetings are examples of calendar items.
Answer the following statement true (T) or false (F)
A class and its members can be described graphically using a notation known as Unified Modeling Language (UML) notation.
Answer the following statement true (T) or false (F)