I have in c-shell some variables referring to file names. Those variables are named like:
$T01aa2 $T12aa2 $T45aa2 etc.
They have in common the "T" and the "aa2".
How can I list these variables in a loop for instance as I would do if they were filenames:
I'd like to do something like:
foreach ii in ($T*aa2) dosomestuff.sh $ii end
Unfortunately, $T*aa2 does not apply for c-shell variable names.
thanks for any help.
Asked
Active
Viewed 45 times
0

user1819779
- 21
- 1
2 Answers
1
Variable names are very different from file names. There is almost certainly a better way to do whatever it is you're trying to do.
But if you must do it, the best you can do is something with set | grep
(or awk
or sed
or whatever) and maybe eval
. Something like this:
set vars=(`set | awk '$1 ~ /^T.*aa2$/ {print $1}'`)
foreach var ( $vars:q )
eval 'dosomestuff "$'"$var"'"'
end
You may be able to get the values out of the set
directly and skip the eval
, but it can get tricky if the values may contain spaces.

Mark Reed
- 91,912
- 16
- 138
- 175
0
Not a big fan of csh but did you try escaping $ signs ? I mean substituting a "$" with "\$" ?

MelBurslan
- 2,383
- 4
- 18
- 26