3

I want to ask how to remove path in cygwin. Let's say I have 3 paths:

PATH=path1:path2:path3

I want to remove path2 so it will be:

PATH=path1:path3

But actually i have a lot of path inside and it will painful to rewrite it manually. Any suggestion?

Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77
kreamik
  • 609
  • 2
  • 11
  • 24
  • 1
    See http://stackoverflow.com/questions/370047/what-is-the-most-elegant-way-to-remove-a-path-from-the-path-variable-in-bash – favoretti Feb 26 '13 at 04:07

1 Answers1

2

A simple solution is to use the bash or csh command-line:

   export PATH=`echo $PATH | sed s/:path2//`

But this will only work 99.9% of the time. To handle the edge cases, such as when path2 is at the start, or when it is part of another path, you'll need:

   export PATH=`echo $PATH | sed "s/:path2:/:/g;s/^path2://;s/:path2$//"`
Joseph Quinsey
  • 9,553
  • 10
  • 54
  • 77