On Thursday 12 January 2006 12:47 pm, Jake Peavy wrote:
> On 1/12/06, Mark Phillips <[EMAIL PROTECTED]> wrote:
> 
> > There is a column in my table with string values, but the strings have
> > spaces
> > in them. I want to read the unique column values into an array in my bash
> > script, so I can use these values in a separate query on this table. How
> > do I
> > get the values into an array?
> >
> > For example, the column teams in my table
> >
> > | team |.....
> > Red Sox
> > Chicago Colleens
> > Athletics
> > Kenosha Comets
> > Red Sox
> >
> > <snip>
> >
> > but I get the following array (using the data above)
> >
> > ("Red" "Sox" "Chicago" "Colleens" "Athletics" "Kenosha" "Comets")
> >
> > How do I either (1) add quotes around each row entry returned so I get the
> > right array, or (2) fill the array in a different way?
> >
> > Thanks!
> 
> 
> 
> Use the bash internal variable IFS, Mark:
> 
> OLDIFS=$IFS
> IFS=$'\n'
> for team in `mysql --skip-column-names -B -e "SELECT team FROM teamnames";
> do
>      echo "[$team]";
> done
> IFS=$OLDIFS
> 

I actually ended up with this:

declare TEAM_QUERY="`mysql ${ACCESS_PARAMS} --exec "select distinct team from 
registered order by team"`"

declare -a TEAMS=(`echo "${TEAM_QUERY}"|sed 's/^/"/g'|sed 's/$/"/g'`) 

Thanks for your help!
> enjoy,
> -jp
> 

-- 
Mark Phillips
VP Softball
Arcadia Little League
www.ArcadiaLittleLeague.org
[EMAIL PROTECTED]
602 524-0376

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to