Search code examples
linuxbashpathenvironment-variablescsh

duplicated environment paths after sourcing .cshrc


In my .cshrc, the LD_LIBRARY_PATH was originally like this:

setenv LD_LIBRARY_PATH path_one:$LD_LIBRARY_PATH

I edit my .cshrc to replace path_one with path_two. My file now looks like this:

setenv LD_LIBRARY_PATH path_two:$LD_LIBRARY_PATH

But after reloading the file (source ~/.cshrc), I got both path_one and path_two in the LD_LIBRARY_PATH:

% echo $LD_LIBRARY_PATH
path_two:path_one

I don't want to include path_one in the path. Can anyone tell me an effective way to update the .cshrc file without the need of logging out/logging back in?


Solution

  • When you source your file that assignment line is being run. It is prepending that static value to the current value of the $LD_LIBRARY_PATH variable.

    Source the file three times in a row and you'll add that path to the front three times.

    There isn't a "default" value you can revert to (unless you save one yourself and be careful with it). In short you get to log out and log back in again or manually edit the current value to be what you want it to be (by manually using setenv from the running shell echo "$LD_LIBRARY_PATH" to get the current value and copy and paste from it, etc.).

    That being said there isn't any real harm in having an extra path in $LD_LIBRARY_PATH when it doesn't exist. It just costs an open attempt during application startup (but that should be fairly quick).

    If the path does exist and contains libraries you don't want to use that's a different story of course.