[clue] bash/using variables in variable names

Quentin Hartman qhartman at gmail.com
Fri Jun 21 16:47:59 MDT 2013


Depending on what your purpose for the this script is be aware that arrays
are a fairly new GNU bash-ism, so if you use them your script may not be
portable to other *sh shells that only do POSIX compliance. One relevant
example is dash, which was (and I believe still is) the default invoked by
"sh" on Ubuntu machines.

QH


On Fri, Jun 21, 2013 at 3:26 PM, Mike Bean <beandaemon at gmail.com> wrote:

> Would export work in a script?   Huh...  Arrays make some intuitive
> sense.  Why is it these projects are never as simple as you think they're
> going to be when you start them?
>
> Mike Bean
>
>
> On Fri, Jun 21, 2013 at 3:09 PM, Raymond DeRoo <rderoo at deroo.net> wrote:
>
>> Mike:
>>
>> export is your friend.
>>
>> OK, I am just thoroughly writer's blocked, probably missing something
>> obvious; but who knows.  Anyway, here's my question
>>
>> # node=somenode
>> # echo $node
>> somenode
>> # somenodeVar=5  * // if this works*
>> # echo $somenodeVar
>> 5
>> # $node"Var"=5 *// why doesn't this work?*
>> bash: somenodeVar=5: command not found
>>
>>
>> [16:06:18 rderoo at daggoo ~]$ node=somenode
>> [16:07:03 rderoo at daggoo ~]$ echo $node
>> somenode
>> [16:07:49 rderoo at daggoo ~]$ export "${node}Var"=5
>> [16:07:57 rderoo at daggoo ~]$ echo $somenodeVar;
>> 5
>> [16:07:58 rderoo at daggoo ~]$ echo $somenodeVar;
>>
>>
>> For the time being well skip the discussion on why variable variables are
>> bad and that one should really be using arrays...
>>
>> Kind Regards,
>> Raymond
>>
>> _______________________________________________
>> clue mailing list: clue at cluedenver.org
>> For information, account preferences, or to unsubscribe see:
>> http://cluedenver.org/mailman/listinfo/clue
>>
>
>
> _______________________________________________
> clue mailing list: clue at cluedenver.org
> For information, account preferences, or to unsubscribe see:
> http://cluedenver.org/mailman/listinfo/clue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20130621/ad982a2e/attachment.html 


More information about the clue mailing list