SUMMARY: a possibly even stupider scripting question

From: Danielle Georgette <Danielle.Georgette_at_asx.com.au>
Date: Tue, 09 May 2000 16:55:08 +1000

Problem solved once again. Man eval, and the solutions below.

Thanks to:

Tame, Richard [richard.tame_at_compaq.com]
Thomas, Phil [Phil.Thomas_at_compaq.com]
Michael James Bradford [mjbr_at_tdk.dk]

Tame, Richard [richard.tame_at_compaq.com]

Try this

 eval echo $`echo ${fs}_backup`

This is under korn shell.


Thomas, Phil [Phil.Thomas_at_compaq.com]

Yech! Best to avoid this at any cost in Boune-based shells, but if you
insist... read up on "eval" in the shell documentation, and use something
like this:
        fsnum=D1
        eval echo \$${fsnum}_backup

The "eval" resolves to "echo $d1_backup", and thus accomplishes your task,
but the script gets messy and difficult to debug and maintain. You can set
variables in the same way, for example:
        fsnum=d1
        eval ${fsnum}_backup=true

Have a look at Korn shell arrays. Perhaps this will do the job for you a
bit cleaner. (There are some quirks with arrays, too, so be careful.)

Michael James Bradford [mjbr_at_tdk.dk]

After scratching my head for a few minutes, I came up with the following:

        eval echo $`echo ${fsnum}_backup`

Hope this works for you.

Yup - both styles accomplish the task nicely. Phils approach uses one less
echo though - efficiency winner !

Thanks muchly,

Danielle

+-----------------------------------+---------------------------------+
| Danielle Georgette | Unix is very user friendly, its |
| Unix Admin | just rather particular about |
| danielle.georgette_at_asx.com.au | who it makes friends with. |
+-----------------------------------+---------------------------------+
| All opinions are my own unless clearly stated otherwise. |
+---------------------------------------------------------------------+
 

Question:

Puzzler (for me) number two - its a different script, giving a menu system
to operators allowing them to restore backups. According to the menu option
they pick, a generic restore code takes different options and will or won't
restore the current filesystem. That's the plan, anyway.

I've hit a point where I need a variable to resolve down two 'levels' - ie

the menu option process has set d1_backup=true
the filesystem currently being examined is d1,
so fsnum=d1, and I need to test if
${fsnum}_backup is true

so setup the conditions for this example:
# d1_backup=true
# echo $d1_backup
true
# fsnum=d1
# echo $fsnum
d1
# echo ${fsnum}_backup
d1_backup

and the trouble begins. How the #*_at_!% can I get the assignment to resolve? I
feel kinda poor offloading script questions here thought its been a slow day
on the ol' list so I hope you don't mind.

# tempcase='$'${fsnum}_backup
# echo $tempcase
$d1_backup
# tempcase=$"${fsnum}_backup"
# echo $tempcase
$d1_backup
# tempcase="\$${fsnum}_backup"
# echo $tempcase
$d1_backup
# echo ${tempcase}
$d1_backup
# tempcase=$"$fsnum"_backup
# echo $tempcase
$d1_backup
#echo `echo $tempcase`
$d1_backup

etc..etc..

Any ideas? I'm guessing this one is going to be as simple as the last, but
in the last two days i've read the man sh, csh and ksh pages til its just
dribbles of text in front of my eyes and i'm not getting any further.

Last scripting question from me, I promise!

Danielle
Received on Tue May 09 2000 - 06:57:01 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:40 NZDT