[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OT: Getting MySQL fields with embedded spaces into array

From: Greg Wooledge
Subject: Re: OT: Getting MySQL fields with embedded spaces into array
Date: Wed, 28 Oct 2009 08:38:07 -0400
User-agent: Mutt/

On Wed, Oct 28, 2009 at 06:04:00AM -0400, Gerard wrote:
> table=MyTable
> DECLARE_STATEMENTS=($(mysql ${COM_LINE} -i -e"use ${DB}; SELECT defaults FROM 
> "${table}" WHERE 1;"))

You're populating an array with each word (not each line) of the output
of your mysql command.

> This output is produced:
> declare
> -a
> Obviously, that is not what I want.

(Not obvious to us.  Maybe so to you. ;-) )

> I have tried setting:
>       IFS=$( echo )

$() removes all trailing newlines from the output of the command that
it executes.  You're setting IFS to an empty string.  If you want to
set IFS to a newline, use this:


Or this:


> I have been exploring different hacks to make this work. Perhaps
> writing to a file and then using 'READ' to put the data into an array.

'read' is the most flexible way, though you don't need a temporary file
to do this.  I have some more documentation on this approach here:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]