-1

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?

Akanksha_p
  • 916
  • 12
  • 20

1 Answers1

1

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

lordadmira
  • 1,807
  • 5
  • 14