[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: csh: how to use indirect ref to env vars



On Jun 25, 12:40 pm, michael <c...@networkingnewsletter.org.uk> wrote:

> ah, I see rather than testing a variable we try and use it and catch any
> error... it seems to work as you say... although this seems slightly
> more elegant if less easy to add new VarN to:
>
>  if ( $?InMetFiles == 0 || $?InTerFile == 0 {etc}) then
>    echo prob
>    exit -1
>  endif
>
> --

Not quite, see the section for "eval" in the csh man page.  The idea
is to use
eval to re-evaluate the variable after the name substitution.

Here is a cleaner version of the concept:


#!/bin/csh

setenv Var1 3

foreach Vars (Var1 Var2 Var3)
    echo checking $Vars\.\.\.
    setenv temp '${?'$Vars'}'
    eval "setenv temp2 $temp"
    if ( "$temp2" != "1" ) then
        echo $Vars not set \- aborting
        exit 1
    endif
end


Reply to: