0

I have a tcsh puzzle, and would appreciate any help.

When I run:

set faceAttenRuns = (09 13)
set run = $faceAttenRuns[1]
echo $run

This returns: echo 09. Great.

But when I run:

set runTypes    = (sceneLoc faceAtten faceNorm)
set run = $runTypes[2]Runs[1]

This returns: set: No Match. Not great.

How can I make $runTypes[2]Runs[1] return 09, so that 09 can be assigned to the variable run?

Thanks!

1
  • IMO the answer to any csh puzzle is "don't use csh for scripting". seriously, while you may be stuck running existing legacy csh scripts, there is NO good reason to ever write new csh (or tcsh) scripts. Any system that has csh will also have at least a basic sh, and probably a ksh or maybe bash or zsh. even a primitive, non-POSIX sh is better than csh for scripts.
    – cas
    Aug 2, 2017 at 4:39

1 Answer 1

0

You need to create an intermediate variable to perform the operation:

set faceAttenRuns = ( 09 13 )
set runTypes = ( sceneLoc faceAtten faceNorm )
set varname = "$runTypes[2]Runs"
echo "set run = "\$"${varname}[1]:q" # this will show you what is going to be evaluated
eval "set run = "\$"${varname}[1]:q"
echo "result=<$run>"

Result

set run = $faceAttenRuns[1]:q
<09>

Here's a version without employing any intermediate variables:

#!/bin/csh -f

set faceAttenRuns = ( 09 13 )
set runTypes = ( sceneLoc faceAtten faceNorm )

echo "set run = "\$"{${runTypes[2]}Runs[1]:q}"
eval "set run = "\$"{${runTypes[2]}Runs[1]:q}"

echo "result=<$run>"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .