I am having trouble with a Bash program I am trying to enter.
#/bin/bash
get_employee_info ()
{
current_empl_id=`awk $id {print $1} employee_database`
current_last_name=`awk $id {print $2} employee_database`
current_first_name=`awk $id {print $3} employee_database`
current_sex=`awk $id {print $4} employee_database`
current_birthdate=`awk $id {print $5} employee_database`
current_salary=`awk $id {print $5} employee_database`
current_tax=`awk $id {print $2} tax_table`
return 0;
}
update ()
{
echo "Do you need a list of employees?"
read list
if [ $list == "y" || $list == "Y" ]
then
cat employee_database | more
fi
echo "Which employee do you want to change?"
read id
get_employee_info
echo "Which aspect of employee $id do you wish to change:"
echo "1. Change last name"
echo "2. Change first name"
echo "3. Change sex"
echo "4. Change birthday"
echo "5. Change salary"
read choice
case $choice in
1)
echo "What is th enew last name of $id:"
read current_last_name;;
2)
echo "What is the new first name of $id:"
read current_first_name;;
3)
echo "What is the new sex of $id:"
read current_sex;;
4)
echo "What is the new birthdate of $id in mm/dd/yyyy format:"
read current_birthdate;;
5)
echo "What is the new salary of $id:"
read current_salary;;
*)
echo "Choice not understood";;
esac
awk "$id employee_database" | sed 'd'
cat "${id}\t${current_last_name}\t${current_first_name}\t${current_sex}\t${current_birthdate}\t${current_birthdate}" >> employee_database
return 0;
}
new_record ()
{
echo "Please enter the employee\'s name, last name first:"
read last_name, first_name
echo "Please enter the ${last_name}\'s id number:"
read empl_id
echo "Please enter the ${last_name}\'s sex:"
read sex
echo "Please enter ${last_name}\'s birthdate in format mm/dd/yyyy:"
read birthdate
echo "Please enter ${last_name}\'s salary"
read salary
if [ salary > 326450 ]
then
tax_rate=(echo"scale=2;$salary \* .33" | bc)
elif [ salary > 150150 ]
then
tax_rate=(echo"scale=2;$salary \* .28" | bc)
elif [ salary > 71950 ]
then
tax_rate=(echo"scale=2;$salary \* .25" | bc)
elif [ salary > 29700 ]
then
tax_rate=(echo"scale=2;$salary \* .15" | bc)
elif [ salary > 7300 ]
then
tax_rate=(echo"scale=2;$salary \* .1" | bc)
else
tax_rate=0
fi
if [ -w employee_database == 0 ]
then
cat "${empl_id}\t${last_name}\t${first_name}\t$sex\t$birthdate\t$salary" >> employee_database
else
cat "${empl_id}\t${last_name}\t${first_name}\t$sex\t$birthdate\t$salary" > employee_database
fi
if [ -w tax_table == 0 ]
then
cat "${empl_id}\t${tax_rate}" >> tax_table
else
cat "${empl_id}\t${tax_rate}" > tax_table
fi
return 0;
}
query ()
{
echo "Do you need a list of employees?"
read list
if [ $list == "y" || $list == "Y" ]
then
cat employee_database | more
fi
echo "Please enter the employee\'s id number"
read id
get_employee_info
echo;echo;echo
echo "The statistic of employee # $id are as follows:"
echo "The last name is ${current_last_name}"
echo "The first name is ${current_first_name}"
echo "The sex is ${current_sex}"
echo "The birthday is ${current_birthdate}"
echo "The salary is ${current_salary}"
echo "The tax due is ${current_tax}"
return 0;
}
menu ()
{
clear
echo "Welcome to the DataBase Program"
echo;echo;echo
any_more="y"
while [ $any_more == "y" || $any_more == "Y" ];
do
echo "Please select from an option below:"
echo "1. Input data for a new employee"
echo "2. Query for a particular employee"
echo "3. Update a record"
echo "x to exit"
read choice
case $choice in
1)
new_record;; <-- I get an error here,
2)
query;; <-- and here. Bash says that these commands can't be found. These functions are defined further up in this file. Have I defined the functions in a wrong manner?
3)
update;;
*)
return;;
esac
echo "Any more records to input?"
read any_more
done
return 0;
}
menu