Another BASH Scripting question

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Mon Feb 9 18:40:44 UTC 2004


| From: Chris F.A. Johnson <c.f.a.johnson-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org>
| On Mon, 9 Feb 2004, Madison Kelly wrote:

|     Use eval:
| 
| eval var=${server}_SNAT_IP
| echo "$var | { .......

If I understand what you are suggesting, then it does not work:

    $ server=SRV2
    $ SRV2_IB_TCP="22 80"
    $ eval var=${server}_SNAT_IP
    $ echo $var
    SRV2_SNAT_IP

I think that this is closer to what is needed:
    $ eval z='$'${server}_IB_TCP
    $ echo $z
    22 80

How can you read this ugly eval?
The operand expands into z=$SRV2_IB_TCP
And then it is evaluated.
The single quotes prevent the enclosed $ from being "executed" during operand
expansion.

My personal religion frowns on eval.  eval is a rather powerful,
subtle, dangerous, and confusing instument.  Anything involving IFS is
also somewhat suspect.

If I'd designed the Bourne Shell, the following would work:

    $ echo ${${server}_IB_TCP}
    bash: ${${server}_IB_TCP}: bad substitution

Hugh Redelmeier
hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org  voice: +1 416 482-8253

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list