I have a function in a script of mine which is supposed to read a list of email addresses from a file called,mail.lst and display them as a menu and prompt the user to select a desired email address by choosing the corresponding number beside it in the menu it shows.The problem is,somehow the script is skipping this and then proceeds to the next statement.Hence,its not displaying that list of email addresses in the file as a menu to select one of them.I am pasting the function here and also the desired output:
FUNCTION:
##########################################
ck_mail_list()
{
i=1
cat Mail/mail.lst | while read LINE
do
if [ `expr "$LINE" : '#'` -ge 1 ]; then
continue
else
address[$i]="$LINE"
i=`expr $i + 1`
fi
done
print -n "Please choose one of the number in front of the address in the following, where\n"
print -n "you want the log file to be sent to. \n"
print -n " \n"
print -n "0) Eneter you own email address;\n"
j=1
while [ $j -lt $i ]
do
print -n "$j) ${address[$j]}; \n"
j=`expr $j + 1`
done
read num_chosen
if [ $num_chosen = 0 ]; then
print -n "Please enter the email address that you want the log file will be sent to: \n"
read email_addr
else
max_choices=`expr $j - 1`
if [ ${num_chosen} -gt ${max_choices} ]; then
print -n "You have picked a wrong choice, we are going to exit. \n"
exit
fi
email_addr=${address[$num_chosen]}
fi
}
#############################################
DESIRED OUTPUT:
Please choose one of the number in front of the address in the following, where
you want the log file to be sent to.
0) Eneter you own email address;
1)
appdba@xyz.com;
2)
app2@xyz.com;
3)
app3@xyz.com;
4)
app4@xyz.com;
5)
app5@xyz.com;
4
Please enter the change reference code for this change:
####################################################
The above should be what I want to see.But,instead It displays the below:
Please choose one of the number in front of the address in the following, where
you want the log file to be sent to.
0) Enter you own email address;
#####################################################
Any help would be appreciated.If anyone of you could point out as what is the mistake in the script or if I am missing something.
Thanks in advance.