SCIENTIFIC-LINUX-USERS Archives

June 2014

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mark Stodola <[log in to unmask]>
Reply To:
Mark Stodola <[log in to unmask]>
Date:
Sat, 7 Jun 2014 11:40:06 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (31 lines)
On 6/7/2014 11:25 AM, Nico Kadel-Garcia wrote:
> On Fri, Jun 6, 2014 at 11:52 PM, ToddAndMargo<[log in to unmask]>  wrote:
>> Hi All,
>>
>> In Bash script language, how do I create a variable name
>> from a variable?
>>
>> I am trying to create a variable called "abcStatus"
>>
>> x=abc
>> $xStatus=xyz
>>
>> obviously doesn't work.  What am I doing wrong?
>>
>> Many thanks,
>> -T
> It's not really core to Scientific Linux itself, but:
>
> For most bash cases where I've found myself wanting something like
> this, I've usually wound up using "hashes" instead. The first hash,
> abc, contains a list of variable names, abcstatus, abctime, abcdate,
> abcowner, etc. that can then be referrenced to refer to other valures
> or hashes as needed.
I agree with everything said so far, but would like to toss in a chapter 
from the Advanced Bash-Scripting Guide (ABS).
The dangers are of course still present, but might give a bit better 
explanation about what is going on.  I actually do have scripts I use 
that utilize the \$$var method.

http://www.tldp.org/LDP/abs/html/ivr.html

ATOM RSS1 RSS2