I have the following bash script:
MYSQL="which mysql"
SQL="CREATE DATABASE IF NOT EXISTS TEST;"
read -p -s "Enter mySQL password:" DBPASS
$MYSQL -root -p$DBPASS -e "$SQL"
if [ "$?" -eq 0 ];
then
echo "Failed."
else
echo "Done."
fi
Even if I type wrong password the script says "Done.", as it can´t detect the mysql command error...
I need to be able to correctly show the "Error." message when someone types a wrong password.
Help appreciated.
expect- expect.sourceforge.net - would be a better betMYSQL="which mysql"byMYSQL="$(which mysql)".$(which mysql)did not solved the problem...which mysqland the MySQL username must after -u. so -uroot