function pathremove()
{
local P=:$1:; shift
while [ "$1" ]; do P=${P/:$1:/:}; shift; done
P=${P#:}; P=${P%:}
echo ${P}
}
function pathprefix()
{
local P=$(pathremove $@); shift
local N=""
for n in $@; do N=${N}:$n; done
echo "${N#:}:${P}"
}
function pathsuffix()
{
local P=$(pathremove $@); shift
local N=""
for n in $@; do N=${N}:$n; done
echo "${P}${N}"
}
Example usage:
export PATH=$(pathsuffix $PATH $HOME/bin /opt/bin)
export PATH=$(pathremove $PATH /sbin)
export LD_LIBRARY_PATH=$(pathprefix $LD_LIBRARY_PATH /opt/lib)
No comments:
Post a Comment