Re: [SLUG] Shell stuff

From: Paul M Foster (paulf@quillandmouse.com)
Date: Mon Dec 22 2008 - 22:05:37 EST


On Mon, Dec 22, 2008 at 09:46:48PM -0500, Dylan William Hardison wrote:

> You want arrays:
>
> PANTS=($(echo -e "foo\nbar\nbaz"))
>
> echo ${PANTS[0]}
> echo ${PANTS[1]}
> echo ${PANTS[2]}

Now, that's weird. I tried this as:

MYVAR=$(somecommand)

but it stuck everything in the first position of MYVAR (index 0). When I
surround the whole thing with a pair of parentheses as you did, it
works! Thanks. I don't understand why it works, but it does.

>
> Spake Paul M Foster on Monday, December 22, 2008 at 09:14PM -0500:
> > Here's a shell question I can't find the answer to. I have a command
> > that returns a set of newline-delimited values to a single variable.
> > Effectively, it looks like this:
> >
> > MYVAR=alfa
> > bravo
> > charlie
> > delta
> > echo
> >
> > I want to split those values out and into separate shell variables that
> > I can use for other things. In the end, it would look like this:
> >
> > MYALFA=alfa
> > MYBRAVO=bravo
> > MYCHARLIE=charlie
> > MYDELTA=delta
> > MYECHO=echo
> >
> > I can't find any bash facility which does this. Anyone know how to do
> > it?
> >
> > Paul
> > --
> > Paul M. Foster
> > -----------------------------------------------------------------------
> > This list is provided as an unmoderated internet service by Networked
> > Knowledge Systems (NKS). Views and opinions expressed in messages
> > posted are those of the author and do not necessarily reflect the
> > official policy or position of NKS or any of its employees.
>
> --
> We're here to give you a computer, not a religion.
> -- attributed to Bob Pariseau, at the introduction of the Amiga
> -
> GPG Fingerprint: 1AD8 69DD F56A E7AB 421C 7D8A C66D 87D9 82CD 4AE4.
> -----------------------------------------------------------------------
> This list is provided as an unmoderated internet service by Networked
> Knowledge Systems (NKS). Views and opinions expressed in messages
> posted are those of the author and do not necessarily reflect the
> official policy or position of NKS or any of its employees.

-- 
Paul M. Foster
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 18:06:20 EDT