Shell脚本语法错误没有删除mysql

时间:2016-09-26 07:21:38

标签: mysql bash shell

输出:错误语法我不知道位置语法错误也许你可以帮助我!

[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脚本:我的新shell脚本只是语法错误,但我无法编辑代码

#!/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

2 个答案:

答案 0 :(得分:1)

在下面的部分中将'更改为',如下所示;

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);" ;;

答案 1 :(得分:1)

您只需在日期格式中使用"和其他参数:

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);' ;;