I want to send a number of predefined queries to mysql. i will use the variable defined internally by using the externally inputted variable as below. But not good.
[testuser@testserver work]$ cat test1.sh
#!/bin/sh
query1='select * from mysql.user limit 2;'
query2="select * from mysql.user limit 2;"
echo $1
echo "$1"
#mysql -uuser-p -e "$1"
this is result
[testuser@testserver work]$ sh test3.sh query1
query1
query1
but i want result
[testuser@testserver work]$ sh test1.sh query1
select * From mysql.user limit 1
how to modify this bash scrpit?
echo "${!1}"syntax!query1andquery2, you can usesource test1.sh; echo query1, if you just want to retrieve it, I would use acasestatement.$1is the first parameter to your script. You pass query1 as parameter, so of course query1 is printed by theechostatement.