0

Maybe I'm thinking about this wrong, but I want to add Python to my $PATH variable if it isn't already in there.

Here's my code

# Add Python to $PATH
if(-e /path/to/python/bin && (! $PATH.Contains('python')) then
    set path=($path:/path/to/python/bin)
else
    echo 'ERROR: Unable to find the path to Python executable in .cshlc!'
endif
2

One simple way, with a couple minor improvements:

if (-d /path/to/python/bin && "$path" !~ *"/path/to/python/bin"*) then
    set path=($path /path/to/python/bin)
else
    echo 'ERROR: Unable to find the path to Python executable in .cshlc!'
endif

I changed -e to -d, to be a slightly stronger test for a directory's existence, then I check to see if the $path variable contains anything like /path/to/python/bin; if the directory exists and the path variable does not yet contain that path, then append it. I believe csh syntax uses spaces to separate elements in the path, not colons.

  • Yes, csh use spaces to separate path elements in the variable $path, however, the variable $PATH use colons : (as is usual). – Isaac May 1 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.