I have a $empIc which is a variable input by the user. I try to read some details from a text file and do checking on variable $ic. If the input does not match, script file invalidic will be executed where it let the user to choose to reenter the input or back to menu. However, the read command in the invalidic script is never executed and resulted in an infinite loop.
while IFS=':' read -r dep ic name phone email gender birthDate jobTitle joinDate
do
if [ "$empIc" = "$ic" ]
then
echo -n "Employee Name : $name"; echo
echo -n "Job Title : $jobTitle"; echo
echo -n "Department : $dep"; echo
break
else
match=0
fi
case $match in
0) echo "No such record!"; ./invalidic; break;;
*)
esac
done <Employee.txt
This is the code for invalidic script file:
#!/bin/bash
while true
do
echo "========================================="
echo "1. Enter Performance Review again"
echo "2. Back to Human Resource Management Menu"
echo "========================================="
echo "What would you like to do? Please enter choice in number: "; read action
case $action in
1) ./task4_main; break;;
2) ./task1_menu; break;;
*) echo "Please enter 1 for Performance Review, 2 to back to Human Resource Management Menu"
esac
done
This is the output I get when the input does not match with data stored
./invalidicwith./invalidic </dev/null.readinsideinvalidcis not executed? You should see the output from theechostatement, than theread actionconsumes the next line fromEmployee.txt, because this is the standard input at this moment, and since Employee.txt probably does not contain a line having just1or2, you should see thePlease enter ...message and the loop is restarted. However this is not done endlessly, but only until Employee.txt has been exhausted. Then the program should terminate.