Aqui está a versão de trabalho da função
function executeMySql() {
local password
local prompt
local char
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'echo -e "Enter your mysql \$root password to create the db"
while ! executeMySql "CREATE DATABASE IF NOT EXISTS Test" "Test db ready"; do :; done
' ]]; then
break
elif [[ $char == $'7' ]]; 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
echo -e "SUCCESS: $2"
else
echo -e "Wrong password try again"
fi
return $ret;
}
exemplo de uso
function executeMySql() {
local password
local prompt
local char
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'echo -e "Enter your mysql \$root password to create the db"
while ! executeMySql "CREATE DATABASE IF NOT EXISTS Test" "Test db ready"; do :; done
' ]]; then
break
elif [[ $char == $'7' ]]; 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
echo -e "SUCCESS: $2"
else
echo -e "Wrong password try again"
fi
return $ret;
}