How to keep from duplicating path variable in csh

前端 未结 12 906
我在风中等你
我在风中等你 2020-11-27 05:19

It is typical to have something like this in your cshrc file for setting the path:

set path = ( . $otherpath $path )

but, the path gets dup

12条回答
  •  借酒劲吻你
    2020-11-27 06:05

    Here's what I use - perhaps someone else will find it useful:

    #!/bin/csh
    #  ABSTRACT
    #    /bin/csh function-like aliases for manipulating environment
    #    variables containing paths.
    #
    #  BUGS
    #    - These *MUST* be single line aliases to avoid parsing problems apparently related
    #      to if-then-else
    #    - Aliases currently perform tests in inefficient in order to avoid parsing problems
    #    - Extremely fragile - use bash instead!!
    #
    #  AUTHOR
    #    J. P. Abelanet - 11/11/10
    
    #  Function-like alias to add a path to the front of an environment variable
    #    containing colon (':') delimited paths, without path duplication
    #
    #  Usage: prepend_path ENVVARIABLE /path/to/prepend
    alias prepend_path \
      'set arg2="\!:2";  if ($?\!:1 == 0) setenv \!:1 "$arg2";  if ($?\!:1 && $\!:1 !~ {,*:}"$arg2"{:*,}) setenv \!:1 "$arg2":"$\!:1";'
    
    #  Function-like alias to add a path to the back of any environment variable 
    #    containing colon (':') delimited paths, without path duplication
    #
    #  Usage: append_path ENVVARIABLE /path/to/append
    alias append_path \
      'set arg2="\!:2";  if ($?\!:1 == 0) setenv \!:1 "$arg2";  if ($?\!:1 && $\!:1 !~ {,*:}"$arg2"{:*,}) setenv \!:1 "$\!:1":"$arg2";'
    

提交回复
热议问题