Hi,

I'm trying to check if the user that im deleting exist in the database before deleting them, but it does not recognise the id (delID) the second time that i enter the id (even if it is right).

Any suggestion

delete(){
clear
echo "-------------"
echo "DELETE RECORDS"
echo "-------------"
read -p "Please enter staff id that you wish to delete: " delID

indelID=$(grep $delID ~/appraisal/work.db | cut -d":" -f1)
surname=$(grep $delID ~/appraisal/work.db | cut -d":" -f2)
name=$(grep $delID ~/appraisal/work.db | cut -d":" -f3)

while [[ "$(echo $delID | grep -c '^[0-9][0-9][0-9]$')" = 0 || $delID = $inlID ]]
do
read -p "The staff ID entered is incorrect, please try again: " delID
done
echo "Would you like to delete $name $surname from the database? (press y or n)"
read ans

if [[ $ans = y* || $ans = Y* ]]
then
sed -i "/$delID/d" ~/appraisal/work.db
echo "record deleted!"
else [$ans != n ]
menu
fi
read -p "Press return access the main menu " main
menu
}

Thanks

@Rizzuti:
You tried running the file as root?

sudo script
commented: Report spam, don't reply to it or your posts are likely to be edited/deleted along with the spam. -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.