The following script
#!/bin/bash
QUERY='select * from cdr;'
MYROWS=$("sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db '${QUERY}'")
gives me
./bla.sh: row 35: sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db 'select * from cdr;': file or directory not found
If I execute directly
sqlite3 -list -nullvalue NULL -separator ',' /var/log/asterisk/master.db 'select * from cdr;'
then it works. I guess there is some error with the quotes that can't be seen on the error message. Please note that I need the single quotes around
select * from cdr;
Thanks for any hint on what I am doing wrong!
MYROWS=$(sqlite3 ... "${QUERY}"). You don't need single quotes because you have captured the special characters in the previous line. – forcefsck Sep 9 '12 at 21:37select * from cdr;as a parameter to sqlite3. You need to use quotes (single or double) so the shell will pass it as one parameter, not because sqlite3 requires it. Because you need${QUERY}to be expanded, you have to use double quotes in this case. – forcefsck Sep 10 '12 at 14:31