Problem with dynamic statement in bash

From: Burkhard Schultheis <burkhard.schultheis_at_web.de>
Date: Fri, 19 Jan 2018 10:24:22 +0100
Message-ID: <p3sdg6$vti$1_at_news.albasani.net>



[Quoted] [Quoted] Because I must select from several tables depending on the time range I [Quoted] must create a dynamic mysql statement in bash. If I execute the generated statement in bash, it works. But if I have it in an environment variable $statement execute it with $($statement), mysql gives the error "mysql: unknown option '--print-defaults'".

The statement looks like this:

mysql <databasename> -N -h <hostname> -e "(select distinct <column1>, left(<column2>, locate('[', <column2>)) as versions from <tables1> where
<condition>) union distinct (select distinct <column1>, left(<column2>,
locate('[', <column2>)) as versions from <table2> where <condition>) order by versions;"

This statement works.

But if I try the following:
statement="mysql <databasename> -N -h <hostname> -e \"(select distinct
<column1>, left(<column2>, locate('[', <column2>)) as versions from
<tables1> where <condition>) union distinct (select distinct <column1>,
left(<column2>, locate('[', <column2>)) as versions from <table2> where
<condition>) order by versions;\""

$($statement)

I get the error "mysql: unknown option '--print-defaults'".

As you can see, I've escaped the two quotation marks.

What's wrong? What to change?

Thanks in advance!

Regards
Burkhard Received on Fri Jan 19 2018 - 10:24:22 CET

Original text of this message