Re: Problem with dynamic statement in bash

From: Burkhard Schultheis <burkhard.schultheis_at_web.de>
Date: Thu, 1 Feb 2018 13:50:14 +0100
Message-ID: <p4v2e5$638$1_at_news.albasani.net>


Am 19.01.2018 um 21:00 schrieb Peter H. Coffin:

> On Fri, 19 Jan 2018 10:24:22 +0100, Burkhard Schultheis wrote:

>> Because I must select from several tables depending on the time range I
>> must create a dynamic mysql statement in bash.
> 
> Well, there's your problem.... :)
> 

>> 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)
> 
> Do an echo $statement here instead. I bet you will find your error.
> 

In the meantime I've solved it. I put the statement in a file and executed mysql database < file

Regards
Burkhard Received on Thu Feb 01 2018 - 13:50:14 CET

Original text of this message