bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: remove paths


From: Padraig Brady
Subject: Re: remove paths
Date: Fri, 20 Jul 2001 16:09:08 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2) Gecko/20010628

?
newpath=`echo $PATH | tr : '\n' | uniq | tr '\n' :`

Paul Jarc wrote:

"MrEye" <notell@hate_spam.com> writes:

How do you remove a directory path from the $PATH variable?


With effort.  I use this function to remove duplicate entries from
PATH and similar variables; season to taste.

function cleanpath {
  local var="${1:-PATH}" oldpath newpath=: entry
  oldpath="${!var}:"
  while [ -n "$oldpath" ]; do
    entry="${oldpath%%:*}"
    oldpath="${oldpath#*:}"
    [ "${entry:0:1}" = / ] && [ -n "${newpath##*:$entry:*}" ] &&
      [ -d "$entry" ] && newpath="$newpath$entry:"
  done
  newpath="${newpath#:}"
  eval "$var"'="${newpath%:}"'
}


paul




reply via email to

[Prev in Thread] Current Thread [Next in Thread]