shell - How to include data from a variable in an interactive MySQL command? -


i'm trying write shell script dumps tables user specified table prefix. following part of script:

variable=vardata mysql -u user -p -n information_schema -e "select table_name tables table_schema = 'dbname' , table_name 'test_$variable%'" 

accessing variable can't work this, because of hard quotes in sql statement, how else can it? tried mysql variables @var, doesn't seem work operator.

you can try like

variable=vardata sql_stmt="select table_name tables table_schema = 'dbname' , table_name 'test_"$variable"%'" mysql -u user -p -n information_schema -e "$sql_stmt" 

hope works

updated: per comment j.doe


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -