Re: Problem with dynamic statement in bash

From: Peter H. Coffin <hellsop_at_ninehells.com>
Date: Fri, 19 Jan 2018 14:00:36 -0600
Message-ID: <slrnp64jj4.d0s.hellsop_at_nibelheim.ninehells.com>


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.

-- 
66. My security keypad will actually be a fingerprint scanner. Anyone 
    who watches someone press a sequence of buttons or dusts the pad 
    for fingerprints then subsequently tries to enter by repeating that
    sequence will trigger the alarm system.  --Evil Overlord List
Received on Fri Jan 19 2018 - 21:00:36 CET

Original text of this message