Hi, I have a csh script in which I'd like to do set up a list of vars
and then to chk each of these are set, something like the below.
However, I can't find the magic incantation that allows to to check
${$Vars} eg if $InMetFiles is set on the first loop - suggestions
welcome!
#!/bin/csh
foreach Vars (InMetFiles InTerFile OutDir)
echo Checking $Vars...
if ( ${?Vars} == 0) then
echo $Vars not set - aborting
exit 1
endif
end
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
06-25-2008, 02:02 PM
Wackojacko
csh: how to use indirect ref to env vars
michael wrote:
Hi, I have a csh script in which I'd like to do set up a list of vars
and then to chk each of these are set, something like the below.
However, I can't find the magic incantation that allows to to check
${$Vars} eg if $InMetFiles is set on the first loop - suggestions
welcome!
#!/bin/csh
foreach Vars (InMetFiles InTerFile OutDir)
echo Checking $Vars...
if ( ${?Vars} == 0) then
echo $Vars not set - aborting
exit 1
endif
end
maybe use "" (empty string) instead of 0 in the comparison.
HTH
Wackojacko
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
06-25-2008, 02:22 PM
michael
csh: how to use indirect ref to env vars
On Wed, 2008-06-25 at 15:02 +0100, Wackojacko wrote:
> michael wrote:
> > Hi, I have a csh script in which I'd like to do set up a list of vars
> > and then to chk each of these are set, something like the below.
> > However, I can't find the magic incantation that allows to to check
> > ${$Vars} eg if $InMetFiles is set on the first loop - suggestions
> > welcome!
> >
> > #!/bin/csh
> > foreach Vars (InMetFiles InTerFile OutDir)
> > echo Checking $Vars...
> > if ( ${?Vars} == 0) then
> > echo $Vars not set - aborting
> > exit 1
> > endif
> > end
> >
>
> maybe use "" (empty string) instead of 0 in the comparison.
but I want to check that $InMetFiles is non-empty and then check
$InTerFile is non-empty, not that $Vars is non-empty...
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
06-25-2008, 03:03 PM
ss11223
csh: how to use indirect ref to env vars
On Jun 25, 9:40 am, michael <c...@networkingnewsletter.org.uk> wrote:
> Hi, I have acshscript in which I'd like to do set up a list of vars
> and then to chk each of these are set, something like the below.
> However, I can't find the magic incantation that allows to to check
> ${$Vars} eg if $InMetFiles is set on the first loop - suggestions
> welcome!
>
> #!/bin/csh
> foreach Vars (InMetFiles InTerFile OutDir)
> echo Checking $Vars...
> if ( ${?Vars} == 0) then
> echo $Vars not set - aborting
> exit 1
> endif
> end
>
> --
> To UNSUBSCRIBE, email to debian-user-REQU...@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
its ugly but I think this works
#!/bin/csh
foreach Vars (Var1 Var2 Var3)
echo checking $Vars...
setenv temp '${'$Vars'}'
setenv temp2 `eval echo 'X'$temp >&/dev/null`
if ( "$status" != "0" ) then
echo $Vars not set - aborting
exit 1
endif
end
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
06-25-2008, 04:38 PM
michael
csh: how to use indirect ref to env vars
On Wed, 2008-06-25 at 08:03 -0700, ss11223 wrote:
> On Jun 25, 9:40 am, michael <c...@networkingnewsletter.org.uk> wrote:
> > Hi, I have acshscript in which I'd like to do set up a list of vars
> > and then to chk each of these are set, something like the below.
> > However, I can't find the magic incantation that allows to to check
> > ${$Vars} eg if $InMetFiles is set on the first loop - suggestions
> > welcome!
> >
> > #!/bin/csh
> > foreach Vars (InMetFiles InTerFile OutDir)
> > echo Checking $Vars...
> > if ( ${?Vars} == 0) then
> > echo $Vars not set - aborting
> > exit 1
> > endif
> > end
> >
> > --
> > To UNSUBSCRIBE, email to debian-user-REQU...@lists.debian.org
> > with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
>
> its ugly but I think this works
>
> #!/bin/csh
>
> foreach Vars (Var1 Var2 Var3)
> echo checking $Vars...
> setenv temp '${'$Vars'}'
> setenv temp2 `eval echo 'X'$temp >&/dev/null`
> if ( "$status" != "0" ) then
> echo $Vars not set - aborting
> exit 1
> endif
> end
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
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
06-25-2008, 05:20 PM
ss11223
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
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
07-07-2008, 12:50 PM
michael
csh: how to use indirect ref to env vars
On Wed, 2008-06-25 at 08:03 -0700, ss11223 wrote:
> On Jun 25, 9:40 am, michael <c...@networkingnewsletter.org.uk> wrote:
> > Hi, I have acshscript in which I'd like to do set up a list of vars
> > and then to chk each of these are set, something like the below.
> > However, I can't find the magic incantation that allows to to check
> > ${$Vars} eg if $InMetFiles is set on the first loop - suggestions
> > welcome!
> >
> > #!/bin/csh
> > foreach Vars (InMetFiles InTerFile OutDir)
> > echo Checking $Vars...
> > if ( ${?Vars} == 0) then
> > echo $Vars not set - aborting
> > exit 1
> > endif
> > end
> >
> > --
> > To UNSUBSCRIBE, email to debian-user-REQU...@lists.debian.org
> > with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
>
> its ugly but I think this works
>
> #!/bin/csh
>
> foreach Vars (Var1 Var2 Var3)
> echo checking $Vars...
> setenv temp '${'$Vars'}'
> setenv temp2 `eval echo 'X'$temp >&/dev/null`
> if ( "$status" != "0" ) then
> echo $Vars not set - aborting
> exit 1
> endif
> end
>
it only works if csh is invoked without -e (stop on error)
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org