tcsh: Append to variable if it exists, create if it doesn't exist

0

I'm using a tcsh shell which I'm new to. I'm trying to append a string to a variable if it exists, or create it if doesn't exist. The way I would do this in bash would be:

export PYTHONPATH=${PYTHONPATH}:/my/new/path

However, when I do the equivalent in tcsh

setenv PYTHONPATH ${PYTHONPATH}:/my/path

I get the error PYTHONPATH: Undefined Variable and it does not set the variable to anything. I could of course write conditional logic to set it, but I was wondering if there was an easier way in tsch

if ($?PYTHONPATH == 0) then
    setenv PYTHONPATH /my/path
else
    setenv PYTHONPATH ${PYTHONPATH}:/my/path
end

nanotek

Posted 2019-08-26T16:58:57.437

Reputation: 101

No answers