Passing a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish...

. $X='grep foo blah.log'
then 'mysql command SELECT foo FROM bar WHERE ' . $X

or something like that.

This is part of my script:

cid=$(awk '{ print $2 }' /home/test.txt | sed -n 2p)
echo "cid is" $cid
cat /home/my2.sql | /home/build/env/util/connectdb.sh biller > /home/test2.txt
cat /home/test2.txt

In the my2.sql file:

select * from Notifications join Events using (EventId) where CustomerId = '&cid';

Any suggestions? Possible? If so what am I doing wrong?

Thanks

David

what shell are you using??

cid=`awk 'NR==2{print $2}' /home/test.txt `
echo "cid is" $cid

rest that cat and piped to dbconnect i didn't understand

and if cid is variable use $cid not &cid

select * from Notifications join Events using (EventId) where CustomerId = '$cid';

I'm using Bash.

For the code: cat /home/my2.sql | /home/build/env/util/connectdb.sh biller > /home/test2.txt

I'm passing the query after connecting to the database and then passing the result to the test2.txt file. Not sure if this is the correct way.