How to keep from duplicating path variable in csh

前端 未结 12 947
我在风中等你
我在风中等你 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 05:56

    I have the same need as the original question. Building on your previous answers, I have used in Korn/POSIX/Bash:

    export PATH=$(perl -e 'print join ":", grep {!$h{$_}++} split ":", "'$otherpath:$PATH\")
    

    I had difficulties to translate it directly in csh (csh escape rules are insane). I have used (as suggested by dr_pepper):

    set path = ( `echo $otherpath $path | tr ' ' '\n' | perl -ne 'print $_ unless $h{$_}++' | tr '\n' ' '`)
    

    Do you have ideas to simplify it more (reduce the number of pipes) ?

提交回复
热议问题