mysql script in shell using variables

I would like to use mysql syntax in my shell scripts with variables, what am I using wrong ?

#!/bin/bash

mysql <MyBlaBlaDB> -e "select * from table where something = &1"

and I’m trying to run it as ./test.sh

Answer

try this way,

#!/bin/bash

something="anyting"
mysql -u [username] -p[password] [datbase name] -e "select * from table where something = $something"

Leave a Reply

Your email address will not be published. Required fields are marked *