Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

[Solved] Backtick and escapes

$
0
0
Hello all,
I have a problem with a bash script. It contains an MySQL query, which when I run it 'as is', executes without a problem.

When, however, I try to get it to assign its output to a variable, using the backtick, I get errors.

So ..

Code:

/usr/bin/mysql -N -B mydatabase -e 'SELECT COUNT(*)
FROM orders as o JOIN users as u ON o.userthing=u.package
WHERE o.table BETWEEN (now() - INTERVAL 1 day) AND
now() - INTERVAL 25 hour) AND o.p_stateorder=1 AND
u.name != "The Site" AND u.p_username NOT LIKE "myAddress@mailserver.com";'

.. no problem.

When, however ...

Code:

result=`/usr/bin/mysql -N -B mydatabase -e 'SELECT COUNT(*)
FROM orders as o JOIN users as u ON o.userthing=u.package
WHERE o.table BETWEEN (now() - INTERVAL 1 day) AND
now() - INTERVAL 25 hour) AND o.p_stateorder=1 AND
u.name != "The Site" AND u.p_username NOT LIKE "myAddress@mailserver.com";'`

.. errors.

So I'm guessing that something in there needs to be escaped, but I can't say what.

Can someone help?

Thanks.

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images