I have the following function
function executeMySql() {
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]; then
break
fi
if [[ $char == $'\177' ]]; then
prompt=$'\b \b'
password="${password%?}"
else
prompt='*'
password+="$char"
fi
done
mysql -u root -p$password -e "$1"
ret=$?
if [ $ret = "0" ]; then
# Show success message
printf "\e[32m\nSUCCESS: $2\n\n"
tput sgr0
else
echo "Wrong password"
fi
}
and I use it like this
echo -e "Enter your mysql \$root password to create the db"
executeMySql "CREATE DATABASE IF NOT EXISTS Test" "Test db ready"
{
touch /var/moo.txt
} || {
# ...
}
But if user enters wrong mysql password he receives Wrong password
message and the script continues but what I want is to loop the user password attempts until it's successful and then go on with rest of the script execution.
Any idea how to achieve that?