🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.shell.unix.bourne-bash
Article #12

Re: How to expand variables from string?

#12
From: FrenKy
Date: Sun, 28 Oct 2007 21:38
46 lines
2633 bytes
FrenKy wrote:
> CrispieCritter@gmail.com wrote:
>> On Oct 17, 1:24 pm, Olivier Langlois <olangl...@sympatico.ca> wrote:
>>> Hi,
>>>
>>> First, sorry if I am cross-posting this question. I am not sure to
>>> understand the difference between the 2 newsgroups.
>>>
>>> My problem is that I have a shell variable containing a string
>>> composed of variable names preceded with the expension operator ('$')
>>> and I am fighting with the shell to find a way to make the expension.
>>> Here is an example:
>>>
>>> var1='$HOME'
>>> echo $var1
>>>
>>> will display $HOME but I would like to find a construction that would
>>> allow me to print the $HOME value from the var1 variable.
>>>
>>> Thank you for your assistance,
>>> Olivier 
>>> Langloishttp://www.olivierlanglois.nethttp://blog.olivierlanglois.net
>>
>> Don't enclose the variable with quotes. For example:
>>
>> HOME="Some Random Text"
>> TEST=$HOME
>> echo $TEST
>>
>> This would then print the text "Some Random Text" without quotes which
>> is what you want ?
>>
>> Glenn
>>
> This solution has one problem:
>  HOME="Some Random Text"
>  TEST=$HOME
>  HOME="Some Random Text"
>  echo $TEST
> 
> I'd use Ralf's suggestion.

   HOME="Some Random Text"
   TEST=$HOME
   HOME="Other Random Text"
   echo $TEST
Technical Details
Message-ID: <fg2vft$ro0$1@ss408.t-com.hr>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.germany.com!newsfeed.freenet.de!feed.xsnews.nl!border-2.ams.xsnews.nl!68.142.88.77.MISMATCH!hwmnpeer03.ams!news.highwinds-media.com!txtfeed2.tudelft.nl!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.CARNet.hr!newsfeed.t-com.hr!news3.t-com.hr!not-for-mail
References: <1192591475.543957.112000@k35g2000prh.googlegroups.com> <1192661300.326198.269000@i38g2000prf.googlegroups.com> <fg2p4k$bos$1@ss408.t-com.hr>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114230,e6e9ec2e0724a623
X-Google-Thread: 1054c0,e6e9ec2e0724a623
X-Google-Attributes: gid114230,gid1054c0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.germany.com!newsfeed.freenet.de!feed.xsnews.nl!border-2.ams.xsnews.nl!68.142.88.77.MISMATCH!hwmnpeer03.ams!news.highwinds-media.com!txtfeed2.tudelft.nl!tudelft.nl!txtfeed1.tudelft.nl!newsfeed.CARNet.hr!newsfeed.t-com.hr!news3.t-com.hr!not-for-mail
From: FrenKy <frenky@foo.com>
Newsgroups: alt.comp.lang.shell.unix.bourne-bash,gnu.bash
Subject: Re: How to expand variables from string?
Date: Sun, 28 Oct 2007 22:38:05 +0100
Organization: T-Com
Lines: 46
Message-ID: <fg2vft$ro0$1@ss408.t-com.hr>
References: <1192591475.543957.112000@k35g2000prh.googlegroups.com> <1192661300.326198.269000@i38g2000prf.googlegroups.com> <fg2p4k$bos$1@ss408.t-com.hr>
NNTP-Posting-Host: 89-172-194-237.adsl.net.t-com.hr
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: ss408.t-com.hr 1193607485 28416 89.172.194.237 (28 Oct 2007 21:38:05 GMT)
X-Complaints-To: abuse@t-com.hr
NNTP-Posting-Date: Sun, 28 Oct 2007 21:38:05 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.6 (X11/20071022)
In-Reply-To: <fg2p4k$bos$1@ss408.t-com.hr>