Mit CPC Mit CPC - 2 months ago 6
Bash Question

Shell script syntax error no delete mysql

output : Error Syntax i don't know position syntax error maybe you can help me!

[root@localhost ~]# . test.bash
bash: test.bash: line 23: syntax error near unexpected token `)'
bash: test.bash: line 23: ` 3 ) mysql -u root -p1234 -e 'USE eventime;DELETE FROM eventime.dt WHERE date1 <(SELECT STR_TO_DATE(CONCAT(DATE_FORMAT(now(),\'%Y-%m-%d\'),\'-1\'),\'%Y-%m-%d\')- INTERVAL 90 DAY);' ;;'


Shell Script : I new shell script just syntax error but i can't edit code

#!/bin/bash

selection=
until [ "$selection" = "0" ]; do
echo "=============================="
echo "=========PROGRAM MENU========="
echo "1 - Show Date and Time"
echo "2 - Show Data Database"
echo "3 - Connect Database"
echo ""
echo "0 - Back to command"
echo "=============================="
echo -n "Enter selection : "
read selection
echo ""

case $selection in
1 ) dti=$(date '+%d/%m/%Y %H:%M:%S');
echo "This is Date and Time : " $dti ;;

2 ) mysql -u root -p123456789 -e 'USE eventime;SELECT date1,time1 FROM dt;' ;;

3 ) mysql -u root -p123456789 -e 'USE eventime;DELETE FROM eventime.dt WHERE date1 <(SELECT STR_TO_DATE(CONCAT(DATE_FORMAT(now(),\'%Y-%m-%d\'),\'-1\'),\'%Y-%m-%d\')- INTERVAL 90 DAY);' ;;

0 ) Ctrl+Z ;;
* ) echo "Please enter 1, 2, 3 , 4 or 0"
esac
done

Answer

change ' to " in the following part as below;

3 ) mysql -u root -p123456789 -e "USE eventime;DELETE FROM eventime.dt WHERE date1 <(SELECT STR_TO_DATE(CONCAT(DATE_FORMAT(now(),'%Y-%m-%d'),'-1'),'%Y-%m-%d')- INTERVAL 90 DAY);" ;;