Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $?VAR mean in csh?

Tags:

shell

macros

csh

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?

like image 865
wangshuaijie Avatar asked Jun 07 '13 03:06

wangshuaijie


People also ask

What is $? In csh?

Using variables in a script The $#variable will print out the number of word in the list. And $? variable will return whether it exists. Also, variables names are case sensitive.

How do you set a variable in csh shell?

You use the set or setenv commands to initialize a variable, where set is used for current shell and setenv for current and any subshells (i.e. it will automatically export variables to subshell). setenv should be used for PATH, HOME, and all other system related environmental settings.

What is the significance of dollar parameter?

returns the exit value of the last executed command.

What is .csh file in Unix?

The C shell (csh) is a command shell for Unix-like systems that was originally created as part of the Berkeley Software Distribution (BSD) in 1978. Csh can be used for entering commands interactively or in shell scripts.


2 Answers

$?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.

like image 64
Keith Thompson Avatar answered Oct 23 '22 15:10

Keith Thompson


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

like image 41
High Performance Rangsiman Avatar answered Oct 23 '22 14:10

High Performance Rangsiman