LoginSignup
1
1

More than 5 years have passed since last update.

シェルの$PATHにパスを一時的に追加したり削除したりする

Posted at

一時的にパスを通したい、その後削除したいとき、いちいち $PATH への追加、特に削除がめんどくさい。

適当に関数を追加する。

function addPath() {
  if [ -d $1 ]; then
    export PATH=$1:$PATH
  fi
}

function removePath() {
  if [ -d $1 ]; then
    export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
  fi
}

これで

$ addPath ~/src/foo/bin
$ addPath ~/src/bar/bin

で一時的に追加し、

$ removePath ~/src/foo/bin
$ removePath ~/src/bar/bin

で削除するできるように。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1