From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96079346819488.tru64-unix-managers.marc@archive.invalid> From: Danielle Georgette Date: Tue, 09 May 2000 06:55:08 +0000 To: tru64-unix-managers Subject: SUMMARY: a possibly even stupider scripting question X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96079346819488 Problem solved once again. Man eval, and the solutions below. Thanks to: Tame, Richard [richard.tame@compaq.com] Thomas, Phil [Phil.Thomas@compaq.com] Michael James Bradford [mjbr@tdk.dk] Tame, Richard [richard.tame@compaq.com] Try this eval echo $`echo ${fs}_backup` This is under korn shell. Thomas, Phil [Phil.Thomas@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@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@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 #*@!% 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