Re: [SLUG] Shell stuff

From: Eben King (eben01@verizon.net)
Date: Tue Dec 23 2008 - 11:26:29 EST


On Mon, 22 Dec 2008, Eben King wrote:

> On Mon, 22 Dec 2008, Paul M Foster wrote:
>
>> 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?
>
> command | cut -f 2- -d = | while read line ; do
> caps="$(echo "$line" | tr a-z A-Z)"
> echo "MY$CAPS"="$line"

Oopsie. Obviously untested. Make that
   echo "MY$caps"="$line"

or change the previous line to
   CAPS="$(...)"

> done
>
> Is that what you want?

-- 
A well-lovd and corrctly traind domstc cnine is gnrlly slobbry, excitbl,
noisy, scatologically obsessed, xenophobic, pathetically unjudgmental,
embrrssngly uninhbtd, unreasnngly dvtd, hrtbrkngly dpndnt and wretchedly
craven.  All othr knds of dog cmpre unfvrbly wth ths picture. - PB, AFCA
-----------------------------------------------------------------------
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:07:26 EDT