Elegantly remove a directory from $PATH in Bash shell
removeFromPath() {
local p d
p=":$1:"
d=":$PATH:"
d=${d//$p/:}
d=${d/#:/}
PATH=${d/%:/}
}
Features:
- is pure Bash,
- does not invoke other processes (like 'sed' or 'awk'),
- does not change
IFS
, - does not fork a sub-shell,
- handles paths with spaces, and
- removes all occurrences of the argument in
PATH
.
Written by Robin Bate Boerop
Related protips
1 Response
Could you give an example how to call this function?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#