954,234 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

validation before removing user

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
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

@Rizzuti:
You tried running the file as root?

sudo script
Pjieter
Junior Poster
125 posts since Jan 2012
Reputation Points: 3
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: