What does $?VAR mean in csh?
Asked Answered
I

2

8

I've encountered this code written in csh:

if ( ! $?LM_LICENSE_FILE ) then
    setenv LM_LICENSE_FILE $_LmLicense
else
    switch("$LM_LICENSE_FILE")
    case *${_LmLicense}*:
         breaksw
    default:
         setenv LM_LICENSE_FILE "${_LmLicense}:$LM_LICENSE_FILE"
    endsw
endif

Please note this line:

if ( ! $?LM_LICENSE_FILE ) then

What does $? do in $?LM_LICENSE_FILE?

LM_LICENSE_FILE is a shell variable (or macro, more precisely), and I know that $LM_LICENSE_FILE is used to retrieve its value, but a trailing question mark following $, that is $?LM_LICENSE_FILE, what is its meaning?

Ium answered 7/6, 2013 at 3:55 Comment(0)
M
8

$?VAR expands to 1 (true) if $VAR is set (to anything, even the empty string), 0 (false) if it isn't.

This is documented in the csh manual; follow the link and search for $?, or type man csh or man tcsh.

Oh, and csh doesn't have macros.

Mcfarlane answered 7/6, 2013 at 5:29 Comment(0)
N
1

if ( ! $?LM_LICENSE_FILE ) then
means if ( LM_LICENSE_FILE has not been assigned with any value.) , then ...

On the other hand, if ( $?LM_LICENSE_FILE ) then
means if ( LM_LICENSE_FILE has been defined or assigned.) then

Neron answered 1/7, 2018 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.