Article View: alt.comp.lang.shell.unix.bourne-bash
Article #11Re: How to expand variables from string?
From: FrenKy
Date: Sun, 28 Oct 2007 19:49
Date: Sun, 28 Oct 2007 19:49
39 lines
2335 bytes
2335 bytes
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.
Technical Details
Message-ID:
<fg2p4k$bos$1@ss408.t-com.hr>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.glorb.com!goblin1!goblin.stu.neva.ru!newsfeed.CARNet.hr!newsfeed.t-com.hr!news3.t-com.hr!not-for-mailReferences:
<1192591475.543957.112000@k35g2000prh.googlegroups.com> <1192661300.326198.269000@i38g2000prf.googlegroups.com>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!news2.google.com!news.glorb.com!goblin1!goblin.stu.neva.ru!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 20:49:40 +0100 Organization: T-Com Lines: 39 Message-ID: <fg2p4k$bos$1@ss408.t-com.hr> References: <1192591475.543957.112000@k35g2000prh.googlegroups.com> <1192661300.326198.269000@i38g2000prf.googlegroups.com> 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 1193600980 12060 89.172.194.237 (28 Oct 2007 19:49:40 GMT) X-Complaints-To: abuse@t-com.hr NNTP-Posting-Date: Sun, 28 Oct 2007 19:49:40 +0000 (UTC) User-Agent: Thunderbird 2.0.0.6 (X11/20071022) In-Reply-To: <1192661300.326198.269000@i38g2000prf.googlegroups.com>