I want to remove from the path environment variable all of the enteries that contain a certain word, how can I do that?
2 Answers
export PATH=$(echo $PATH | awk -F : 'BEGIN{ORS=":"}{for (i=1;i<=NF;i++) if ($i !~ /local/) print $i}' | sed 's/.$//')
Will exclude all the $PATH
entries which contain the word "local".
With zsh, where $PATH
is mapped to the $path
array like in csh:
path=( ${path:#*word*} )