Issue
I have a SQL query :
insert into table1 select * from table2
I have to execute this query via shell script which i'm doing in following way:
read -d '' QUERY <<EOF
insert into table1 select * from table2;
EOF
The if i do
echo $QUERY
it prints all files in the directory and that's why this insert is failing. Is there a way i can still use * without shell referencing it to files within that directory?
Solution
The shell globbing on *
would be happening wherever you're using $QUERY
. Apply quotation marks to wherever you might be using $QUERY
.
Better to simply pipe the SQL statement into mysql or whatever it is.
echo "insert into table1 select * from table2" | mysql
Answered By - lordadmira Answer Checked By - David Marino (WPSolving Volunteer)