I try to execute a simple SQL query in a shell script but I had trouble because of the escape of characters
Here is the problem line
#!/bin/sh
su -l mysql -c 'mysql -h XXX.XXX.XX.XXX -uuser -padmin -D testBD -e "SELECT CASE MODE WHEN 0 THEN \'choix1\' WHEN 1 THEN \'choix2\' WHEN 2 THEN \'choix3\' END , count( * ) FROM city GROUP BY name" > /kbd/testSelect'
I have tested this, but I get errors of escaping character that I don t know how to solve
Thank you very much
line 4: syntax error near unexpected token `('
/kbd/test.sh: line 4: ` su -l mysql -c 'mysql -h XXX.XXX.XX.XXX -uuser -padmin -D testBD -e "SELECT CASE MODE WHEN 0 THEN \'choix1\' WHEN 1 THEN \'choix2\' WHEN 2 THEN \'choix3\' END , count( * ) FROM city GROUP BY name" > /kbd/testSelect''
A simple solution is to put the command you want to execute in a separate script:
Then call that script from your original script: