How to check existence of variable in csh

Hi All,

I want to check existence of variable, whose name gets decided dynamically.

E.g. value of this variable,is derived as $option_"exclude" , where value of option varies depending upon user input.

I am trying to do it in a following way :

set exclude_var = `echo $option"_exclude"`
if ( $?$exclude_var ==0 ) then
   echo "Variable not present"
endif

But it gives me error as "Variable Syntax".

Can anyone please explain me where am I going wrong?

Thanks,
Rashmee

==0 should be == 0 ( space between = and 0)

still it is giving same error...

Consider reading this.

I suppose there's a better way (assuming the variable option is always set):

$ set option = ok
$ set ok_exclude = OE
$ eval 'eval if \( \$?${option}_exclude \) echo ok'
ok
$ unset ok_exclude
$ eval 'eval if \( \$?${option}_exclude \) echo ok'
$
1 Like