I'm filtering PATH variables, such that certain elements are deleted (in the example below, it's elements containing the string x86; in practice I'm looking for the string site-packages):
$ echo $(IFS=:;arr=($PATH);echo "${arr[*]//*x86*}")
/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live::/cygdrive/c/Program Files/Lenovo Fingerprint Reader:::/cygdrive/c/Program Files/Intel/iCLS Client:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/cygdrive/c/Program Files/Intel/Intel(R) Management Engine Components/IPT:::::/cygdrive/c/Program Files/Intel/WiFi/bin:/cygdrive/c/Program Files/Common Files/Intel/WirelessCommon:/cygdrive/c/Program Files/Common Files/Lenovo:::/cygdrive/c/SWTOOLS/ReadyApps:::::/usr/lib/lapack
This works pretty well, except that all of the elements which have been zeroed out are still, there, but empty. I'd like to end up with those elements eliminated, and I don't want to use anything other than bash to do it (I know I can use tr, but for portability reasons I would strongly prefer a bash-only solution).
Here's the tr-based solution:
echo $(IFS=:;arr=($PATH);echo "${arr[*]//*x86*}" | tr -s :)
Update: I'm using arrays because I want to be robust in the face of spaces (or anything else other than colons) in the path elements.