Thank you very much Michael, it worked.
Now I see I was overlooking this section in Bash Reference Manual (3.5.3
Shell Parameter Expansion) everytime I was going through it. Stupid me :(
However I see that it works only if ! is the first character after ${
Thus,
#=========================
#!/bin/bash
STRING_1="Value of string one"
STRING_2="Value of string two"
STRING_3="Value of string three"
STRING_4="Value of string four"
for i in `seq 4`; do
echo "Variable is :: STRING_${i}"
# echo "Value is :: ${!STRING_${i}}" # this won't work
tval=STRING_${i}
echo "Value is :: ${!tval}" # Now this would work
done
#=========================
This makes sense to me though, else we would have a lot of ambigous
scenarios.
However, I couldn't figure out what could have been the problem in having it
this way ${STRING_${i}}, that is recursively handle ${${${...}}}
Regards,
irc
----- Original Message -----
From: "Michael Fratoni" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, 11 November, 2002 17:38
Subject: Re: Bash trivia question
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Monday 11 November 2002 06:26 am, irc wrote:
> Hi all,
>
> Probably this isn't the right place to ask Bash questions. But since
> this might be of some relevance to Redhat users I'm posting the
> question here.
>
> Consider the script below:
>
> #=========================================
> !/bin/bash
>
> STRING_1="Value of string one"
> STRING_2="Value of string two"
> STRING_3="Value of string three"
> STRING_4="Value of string four"
>
> for i in ${!STRING*}; do
> echo "Variable is :: ${i}" # output will be: Variable is
> :: STRING_1, STRING_2 ... ... etc.
> echo "Value is :: <???>" # output will be: Value is ::
> Value of string one, Value of string two, ... ... etc.
> done
> #=========================================
>
> My question is what should I write in the place of <???> ?
This should work.
#!/bin/bash
STRING_1="Value of string one"
STRING_2="Value of string two"
STRING_3="Value of string three"
STRING_4="Value of string four"
for i in ${!STRING*}; do
echo "Variable is :: ${i}"
echo "Value is :: ${!i}"
done
- --
- -Michael
pgp key: http://www.tuxfan.homeip.net:8080/gpgkey.txt
Red Hat Linux 7.{2,3}|8.0 in 8M of RAM: http://www.rule-project.org/
- --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9z53Ln/07WoAb/SsRAkLMAJ4wf3mhyXM1FVUJSGGJbBmuvIIs1gCgkFVi
J9wBJ2B+aQZZbu6YmskC0yU=
=19O8
-----END PGP SIGNATURE-----
--
Psyche-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/psyche-list