[Discuss] Bourne Shell variable assignment question

Jerry Feldman gaf at blu.org
Thu Dec 15 16:56:58 EST 2011


On 12/15/2011 04:31 PM, Jerry Feldman wrote:
> On 12/15/2011 04:22 PM, Ben Eisenbraun wrote:
>> On Thu, Dec 15, 2011 at 03:57:04PM -0500, Jerry Feldman wrote:
>>> I have not done my homework on this as much as I should.
>>> A coworker needs to set variable names and values input from another
>>> file. Normally, I would source that file, but he specifically wants to
>>> parse the file.
>>> So, in simple terms, he has a file that has something like:
>>> var1=foo
>>>
>>> Instead of sourcing he wants to parse the file using readline so he
>> Readline is a library for that command line apps can use for command
>> editing and history. It's not part of the shell, and I don't think it can
>> be used the way you're suggesting.
>>
>> -b
>>
>> --
>> the wages of gin is breath.                                  <anonymous>
>>
> I meant read and not readline.
> The real issue is:
> I have a variable called varname that contains "myvar"
> I want to be able to use the content of varname to name a variable so
> that myvar becomes a variable.
> In the specific case, my coworker is reading something like"
> myvar=foo
>
> What he wants to do is the equivalent of sourcing this code, but he
> wants to read it from a file.
> #/bin/sh
> ...
> IFS="=" # This is not the correct way, but I'm just using it as an example
> read varname varvalue
> ### In this case varname contains "myvar", and vavalue contains "foo"
> But, what he wants to end up with is a variable called "myvar"
> containing "foo".
>
> ### What he wants to do does not make sense to me when sourcing the file
> will work just fine.
>
Just want to simplify.
#!/bin/bash
varname=myvar
varvalue=foo
--- do something to create myvar.
myvar=$varvalue
echo $myvar

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90 
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90




More information about the Discuss mailing list