In my prog if i enter the input for the 1st time it is executing correctly,
but for the second time entire script is not executing it just exiting
my code is
#!/bin/sh
checkpo()
{
echo "Checking the entered PO to create output text file ";
IFS=$'\n'
set -f
var=0
for i in $(cat PO_NO.txt)
do
var=`expr $var + 1`
if [ ${#i} -gt 8 ]
then
echo "Error in PO,contains more than 8 char in line number $var with ${#i} characters";
#calling error function
error
elif [ ${#i} -lt 8 ]
then
echo "Erro in PO has less than 8 char in line number $var ";
#calling error function
error
elif [ ${#i} -eq 8 ]
then
echo $i > POF_NO.txt
fi
done
return
#echo " Text file containing PO created successfully ,check POF_NO.txt";
}
error()
{
echo "Do you want to enter PO again ";
echo "If yes press y else press n/N ";
read ANSWER;
if expr "$ANSWER" : "[yY]"
then
echo "Re enter the PO"
#calling main
main
checkpo
elif expr "$ANSWER" : "[nN]"
then
echo "Going to Exit";
exit
fi
return
}
main()
{
echo "Enter the PO's and type exit once you finished !!!!";
while read LINE
do
if [ "$LINE" != "exit" ];then
echo $LINE > PO_NO.txt
else
break 2
fi
done
return
}
#calling main for the first time
main
checkpo
Output is as below
Enter the PO's and type exit once you finished !!!!
1362786278
exit
Checking the entered PO to create output text file
Error in PO,contains more than 8 char in line number 1 with 10 characters
Do you want to enter PO again
If yes press y else press n/N
y
1
Re enter the PO
Enter the PO's and type exit once you finished !!!!
qdqw
exit
after reentering the whole process is not repeating,i dont know where i have commited mistake.Please help me.Thanks in advance.