bug-bash
[Top][All Lists]
Advanced

[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/1.4.2.3i

On Wed, Oct 28, 2009 at 06:04:00AM -0400, Gerard wrote:
> COM_LINE="-u${SQL_USER} -p${SQL_PASSWORD} -h ${HOST} ${NO_COLUMN_NAME}"
> 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
> MSRBL_LIST
> 
> 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:

IFS=$'\n'

Or this:

IFS='
'

> 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:
http://mywiki.wooledge.org/BashFAQ/005




reply via email to

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