Ad
Bash
Code
Diff
  • add_PATH() {
        echo -n "$PATH:$1" | awk 'BEGIN{RS=":";ORS=""}!x[$0]++{if(SEP){print ":"}print $0;SEP=1}'
    }
    
    echo "Original Path: $PATH"
    export PATH=$(add_PATH /usr/local/bin2)
    echo "New Path:      $PATH"
    
    • add_PATH() {
    • t=$(echo $PATH | tr : '\n' | awk '!x[$0]++' | tr '\n' : | sed 's/.$//')
    • echo -n "$t"
    • unset t
    • echo -n "$PATH:$1" | awk 'BEGIN{RS=":";ORS=""}!x[$0]++{if(SEP){print ":"}print $0;SEP=1}'
    • }
    • echo "Original Path: $PATH"
    • export PATH=$(add_PATH /usr/local/bin)
    • echo "New Path: $PATH"
    • export PATH=$(add_PATH /usr/local/bin2)
    • echo "New Path: $PATH"