kwongj@caldwr.UUCP (11/18/87)
To Aegis Users: I have here an Aegis script that prompts a user for a number which is used in part to create variables "dynamically". These variables are created by concatenating a string prefix to the loop counter number. The problem is that I can't evaluate it in the same manner. It appears to be assigning values into the variables since I am able to print out the variable if I explicitly type out the name of the desired variable. --------------------------Aegis script------------------------ #!/com/sh read -prompt "Enter number of elements:" -type integer num args ((^num)) FOR n := 0 to ((^num)) args ((^n)) "var^n" := ^n ENDFOR #Check that other "var"s contain expected values. Assuming you entered #a number greater or equal to 3. args (("This will print out the first element "+ ^var0)) args (("This will print out the third element "+ ^var3)) #args (("This will print out the third element "+ ^var100)) read -prompt "Enter desired element:" -type integer i # # How do you print the value of these 'dynamic' variables ?? #These two statement print the string "vari" where i=number you entered. # args (("var^i")) args ((var^i)) ---------------------------End of Aegis Script------------------- BTW Aegis SR9.5, DN3000s, Domain IX 9.5 James Kwong Calif. Depart. of Water Resources 1416 9 th Street Rm. 249 Sacramento, CA 95802 (916) 322-9430 ucdavis.edu!caldwr!kwongj (Internet) ...!ucbvax!ucdavis!caldwr!kwongj (UUCP) Disclaimer: The opinions expressed above are mine, not those of the State of California or the California Department of Water Resources.
fischer-michael@YALE.ARPA (Michael Fischer) (11/18/87)
I have here an Aegis script that prompts a user for a number which is used in part to create variables "dynamically". These variables are created by concatenating a string prefix to the loop counter number. The problem is that I can't evaluate it in the same manner. Here's a way to evaluate the dynamic variable: args (('args ^var' + ^i)) | sh -e It may not be pretty, but it does write the desired value to standard output. --Mike Fischer -------
ram-ashwin@YALE.ARPA.UUCP (11/18/87)
> I have here an Aegis script that prompts a user for a number which > is used in part to create variables "dynamically". These variables are > created by concatenating a string prefix to the loop counter number. > The problem is that I can't evaluate it in the same manner. > ... > # How do you print the value of these 'dynamic' variables ?? > #These two statement print the string "vari" where i=number you entered. Try this: ------------------------------------------------------------------------------ #!/com/sh eon read -prompt "Enter number of elements:" -type integer num for n := 0 to ^num "var^n" := ^n endfor read -prompt "Enter desired element:" -type integer i /com/sh "args @"The value of var^i is @^var^i@"" ------------------------------------------------------------------------------ I set up the command I want executed (the args command) which includes the name of the variable I want, and then I 'eval' it using /com/sh. -- Ashwin Ram -- ARPA: Ram-Ashwin@cs.yale.edu UUCP: {decvax,linus,seismo}!yale!Ram-Ashwin BITNET: Ram@yalecs