mercredi 6 février 2019

$? tcsh script issue

I am confused with a tcsh shell script issue. (for work, no choice in shell, I'm stuck with it)

The enableThingN items below are shell enviroment variables set by other things before running this csh script, using tcsh shell. These are not set within the same script here at all, only evaluated here.

Error message is:

enableThing1: Undefined variable.

Code is:

if ( ( $?enableThing1  &&  ($enableThing1 == 1) ) || \
     ( $?enableThing2  &&  ($enableThing2 == 1) ) || \
     ( $?enableThing3  &&  ($enableThing3 == 1) ) || \
     ( $?enableThing4  &&  ($enableThing4 == 1) )      ) then

    set someScriptVar  = FALSE
else
    set someScriptVar  = TRUE
endif

So, as I understand things, the first part of the big if condition is to check if enableThing1 is defined at all or not, using the $?enableThing1 magic. If it is defined, then move on and check the value is 1 or something else. If not defined, then skip the ==1 part of the check for the same shell variable, and move on to see if enableThing2 is defined at all or not, and so on.

As it seems like I am checking for existence, and intend to avoid checking value if it is not defined at all, where have I gone wrong?

I have searched here on stackoverflow and on Google at large, but there are few results and don't get me to an answer, such as:

https://stackoverflow.com/questions/16975968/what-does-var-mean-in-csh

Aucun commentaire:

Enregistrer un commentaire