LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   set path problem solved (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/set-path-problem-solved-295334/)

lfur 02-26-2005 10:37 PM

set path problem solved
 
Hi!

Actually this is not a question but rather an answer to my own questions/problems, which I think is worth posting here (thanx to acid_kewpie and Dark_Helmet for suggestions on this topic posted previously).
So here it goes:

this is a (bash) function for checking your path entries for duplicates and that evil dot (.) :)

Code:

function setpath() {
  newpath=""

  for old in $(echo $1 | sed -e "s/:/\n/g" | grep -v "\.")
  do
    if [ -d "$old" ]
    then
      bad=0
      for new in $(echo $newpath | sed -e "s/:/\n/g")
      do
        if [ "$old" == "$new" ]
        then
          bad=1
        fi
      done
      if [ "$bad" == "0" ]
      then
        if [ "$newpath" == "" ]
        then
          newpath=$old
        else
          newpath=${newpath}:$old
        fi
      fi
    fi
  done
 }

... it takes only 1 argument which is a path to test.
To test your $MANPATH you should put:

Code:

setpath "$MANPATH"
export MANPATH=$newpath

after the function ... setting the path to check before it is required :)

Hope this helps anyone - it sure has served me good.

Enjoy,

Luka

XavierP 02-27-2005 05:08 PM

Moved: This thread is more suitable in Success Stories and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 07:44 PM.