I have a username system. The user picks a username, password and pin number and this is saved into UPP.db. I want to be able to parse this text so that a user can either be edited (Change password) or Deleted (Remove Line). I have coded a solution for both but both return me with an error and jump to the "Else" part of my If statement. I will provide the code for the edit section as the delete is pretty similar and would be redundant providing both.
echo "Please enter the username you wish to edit"
read usernamecheck
usernamesearch=$( grep $usernamecheck\$ UPP.db | cut -d" " -f1 )
if [ $usernamecheck = $usernamesearch ]
then
echo "Please enter $usernamesearch PIN"
read pincheck
pinupdate=$( grep $pincheck\$ UPP.db | cut -d" " -f3 )
if [[ $pin = $pinupdate && $usernamecheck = $usernamesearch ]]
then
echo "The user `grep "$pin"\$ UPP.db | cut -d" " -f1`'s password is about to be changed "
echo "Please enter the new password"
read newpass
passwordcheck=$( grep $pincheck\$ UPP.db | cut -d" " -f2 )
sed -i "s/$passwordcheck/$newpass/g" UPP.db
echo "Password changed"
else
echo "The PIN is incorrect"
fi
else
echo "This username is not reconised"
fi
;;
[ ... ]e.g. (if [ "$usernamecheck" = "$usernamesearch" ]) ... and as a general rule everywhere else except inside[[ ... ]]Alsoif [[ $pin = $pinupdate && $usernamecheck = $usernamesearch ]]should beif [[ $pin = $pinupdate ]] && [[ $usernamecheck = $usernamesearch ]][[...]], just not inside[...]