I have the following
--------------------
foreach var (STO SNY WKF)
set ta = 5
end
---------
How can I echo both variables at the same time. Something to the effect of
echo ${$var}ta
But this doesn't work. Seems like it would. Thanks.
I have the following
--------------------
foreach var (STO SNY WKF)
set ta = 5
end
---------
How can I echo both variables at the same time. Something to the effect of
echo ${$var}ta
But this doesn't work. Seems like it would. Thanks.
${var}${ta}
Yeah I didn't phrase my question the way I wanted to. Let me try again.
Given the following:
----------------------
foreach var (t v w)
grep $var ./file > ./newfile
set ${var}temp = `awk '{print $2}' ./newfile`
now this is where I need help
how can I echo each variable with only one echo statement, essentially, do:
echo $ttemp $vtemp $wtemp
But doing this with alot of variables, creates a long script, and is not very efficient.
I've tried the following
echo ${$var}temp, this doesn't work
end
Hopefully this makes more sense than before.
Thanks in advance.
I may not have understood the problem correctly - and it looks a bit artificial, not homework is it? - but it looks as if you trying to set variables where the variable name is created from the loop variable (t, v, w) and 'tmp' (i.e. ttmp, vtmp, wtmp)?
If so then you need to use 'eval' to do the substitutions for the variable name before assigning it a value. Something like:
for var in t v w do
grep $var ./file > ./newfile
eval ${var}tmp=`awk '{print $2}' ./newfile`
eval print ${var}tmp set
done
Note that this will fail if the 'grep' finds more than one matching line
If I've got hold of the wrong end of the twig then try a more detailed explanation of what you are trying to achieve
cheers
Steve
thanks for the help, don't worry it isn't homework.