方便的 shell function:

pathmunge () {
  if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
    if [ "$2" = "after" ] ; then
      PATH=$PATH:$1
    else
      PATH=$1:$PATH
    fi
  fi
  export PATH
}

在設定路徑之前建立這個函式,就可以避免路徑裡出現重複的項目;加以變化,還可以設定其它種類的路徑:

manpathmunge () {
  if ! echo $MANPATH | /bin/egrep -q "(^|:)$1($|:)" ; then
    if [ "$2" = "after" ] ; then
      MANPATH=$MANPATH:$1
    else
      MANPATH=$1:$MANPATH
    fi
  fi
  export MANPATH
}

不知道 Debian 的 /etc/bashrc 裡為何沒有定義。把這個函式加到 ~/.bashrc 裡的話會很方便。

Posted by yungyuc at 20:45, 0 comment, 0 trackback.
Navigate
Add a trackback
Add a comment

Your name. (required)

Your personal website. (optional)

Your email address. Will not show in page. (suggested, but optional)

Text format is "Plain Text".

Enter "zNLQH"
© hover year to navigate month: powered by django