Operating System - HP-UX
1754376 Members
3162 Online
108813 Solutions
New Discussion юеВ

Re: script help : display value of variable parameter

 
SOLVED
Go to solution
patrick xi
Advisor

script help : display value of variable parameter

Dear friends,

Is it possible to display the value of a variable parameter, I make a sample script below. But it can only display the parameter name.

SAMPLE:

FILE1=red
FILE2=black
for i in {1,2}
do
echo $"FILE$i"
let i=i+1
done

I need the output of this line to be
red
black
but it is
$FILE1
$FILE2

Could you help modify so that I could get correct output?
4 REPLIES 4
Warren_9
Honored Contributor
Solution

Re: script help : display value of variable parameter

hi,

using array....

set -A FILE
FILE[1]=red
FILE[2]=black
for i in 1 2
do
echo ${FILE[$i]}
done

GOOD LUCK!!
patrick xi
Advisor

Re: script help : display value of variable parameter

Hi, Warren,

It solved my problem, thank you very much.
Ivan Ferreira
Honored Contributor

Re: script help : display value of variable parameter

Without using an array:

FILE1=red
FILE2=black
for I in 1 2
do
eval echo \"\$FILE$I\"
done
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
patrick xi
Advisor

Re: script help : display value of variable parameter

thread closed.