Suggestion please : adjust the order of pathes in $PATH
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Suggestion please : adjust the order of pathes in $PATH




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Suggestion please : adjust the order of pathes in $PATH  
linq936@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 10:55 PM

Hi,
I am running cygwin with BASH on my windows machine, I find that some
windows tools are of same names with cygwin tools, e.g. find. So I want
to adjust the order of pathes in $PATH, now windows path is before
cygwin path.

Here are the commands in my .bashrc, it works fine, the problem is it
runs slow, each time I start a new cygwin shell, it takes quite a well
to do this adjustment. I wonder if you have any suggestion on the
efficiency?

Thanks.


# Move c:/windows to the end of $PATH
_path=""
_winpath=""
IFS_bak=$IFS
IFS=:
first_w_path=1
first_path=1
for i in $PATH
do
cc=`echo $i|grep -i "/c/windows/"`
if [ ! -z $cc ]
then
if [ $first_w_path == 1 ]
then
_winpath=$i
first_w_path=0
else
_winpath=$_winpath:$i
fi
else
if [ $first_path == 1 ]
then
_path=$i
first_path=0
else
_path=$_path:$i
fi
fi
done
export PATH=$_path:$_winpath
IFS=$IFS_bak






[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
Kurt Swanson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 10:55 PM

linq936@hotmail.com writes:
> Hi,
>   I am running cygwin with BASH on my windows machine, I find that some
> windows tools are of same names with cygwin tools, e.g. find. So I want
> to adjust the order of pathes in $PATH, now windows path is before
> cygwin path.

>   Here are the commands in my .bashrc, it works fine, the problem is it
> runs slow, each time I start a new cygwin shell, it takes quite a well
> to do this adjustment. I wonder if you have any suggestion on the
> efficiency?

> Thanks.


> # Move c:/windows to the end of $PATH
> _path=""
> _winpath=""
> IFS_bak=$IFS
> IFS=:
> first_w_path=1
> first_path=1
> for i in $PATH
> do
>    cc=`echo $i|grep -i "/c/windows/"`
>    if [ ! -z $cc ]
>    then
>       if [ $first_w_path == 1 ]
>       then
>          _winpath=$i
>          first_w_path=0
>       else
>          _winpath=$_winpath:$i
>       fi
>    else
>       if [ $first_path == 1 ]
>       then
>          _path=$i
>          first_path=0
>       else
>          _path=$_path:$i
>       fi
>    fi
> done
> export PATH=$_path:$_winpath
> IFS=$IFS_bak

PATH=$(echo $PATH | sed -e 's./c/windows/*:..g'):/c/windows
--
© 2006 Kurt Swanson AB





[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 10:55 PM

On 2006-03-15, linq936@hotmail.com wrote:
> Hi,
>   I am running cygwin with BASH on my windows machine, I find that some
> windows tools are of same names with cygwin tools, e.g. find. So I want
> to adjust the order of pathes in $PATH, now windows path is before
> cygwin path.
>
>   Here are the commands in my .bashrc, it works fine, the problem is it
> runs slow, each time I start a new cygwin shell, it takes quite a well
> to do this adjustment. I wonder if you have any suggestion on the
> efficiency?
>
> # Move c:/windows to the end of $PATH
> _path=""
> _winpath=""
> IFS_bak=$IFS
> IFS=:
> first_w_path=1
> first_path=1
> for i in $PATH
> do
>    cc=`echo $i|grep -i "/c/windows/"`

Do not use grep (or any external command) to test strings; reserve
it for files. Use case instead.

>    if [ ! -z $cc ]

if [ -n "$cc" ]

>    then
>       if [ $first_w_path == 1 ]
>       then
>          _winpath=$i
>          first_w_path=0
>       else
>          _winpath=$_winpath:$i
>       fi
>    else
>       if [ $first_path == 1 ]
>       then
>          _path=$i
>          first_path=0
>       else
>          _path=$_path:$i
>       fi
>    fi
> done
> export PATH=$_path:$_winpath
> IFS=$IFS_bak

fixwinpath() ## move /c/windows to end of PATH iff it is aleady in $PATH
{
local IFS=: newpath= winpath= p
for p in $PATH
do
case $p in
/[Cc]/[Ww][Ii][Nn][Dd][Oo][Ww][Ss]) winpath=
$p ;;
*) newpath=${newpath:+$newpath:}$p ;;
esac
done
PATH=$newpath${winpath:+:$winpath}
}

--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |          is released under the
2005, Apress                 |     GNU General Public Licence





[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
linq936@hotmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:50 PM

Thanks...but this command has some problem.

It gets rid off all the "/c/windows/*" and add "/c/windows" to the end,
for example, the initial $PATH is
"/cygdrive/c/windows/system32:/usr/bin", after this command, $PATH
becomes "/cygdrive:/usr/bin:/c/windows" which is not right.

Thanks though.






[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:50 PM

On 2006-03-16, linq936@hotmail.com wrote:
> Thanks...but this command has some problem.

What command is that?

Please include context when following up a post. Please read
<http://cfaj.freeshell.org/google> for guidelines on how to post
from Google Groups.

> It gets rid off all the "/c/windows/*" and add "/c/windows" to the end,
> for example, the initial $PATH is
> "/cygdrive/c/windows/system32:/usr/bin", after this command, $PATH
> becomes "/cygdrive:/usr/bin:/c/windows" which is not right.

Was that the script I posted, or someone else's? Whichever it was,
please include it in your followup.

--
Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
Shell Scripting Recipes:     |  My code in this post, if any,
A Problem-Solution Approach  |          is released under the
2005, Apress                 |     GNU General Public Licence





[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
Kurt Swanson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:50 PM

linq936@hotmail.com writes:
> Thanks...but this command has some problem.

> It gets rid off all the "/c/windows/*" and add "/c/windows" to the end,
> for example, the initial $PATH is
> "/cygdrive/c/windows/system32:/usr/bin", after this command, $PATH
> becomes "/cygdrive:/usr/bin:/c/windows" which is not right.

I think you forgot the colon...
--
© 2006 Kurt Swanson AB





[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:50 PM

2006-03-15, 15:12(-08), linq936@hotmail.com:
> Hi,
>   I am running cygwin with BASH on my windows machine, I find that some
> windows tools are of same names with cygwin tools, e.g. find. So I want
> to adjust the order of pathes in $PATH, now windows path is before
> cygwin path.
>
>   Here are the commands in my .bashrc, it works fine, the problem is it
> runs slow, each time I start a new cygwin shell, it takes quite a well
> to do this adjustment. I wonder if you have any suggestion on the
> efficiency?
[...]

Switch to zsh:

~$ echo $PATH
/usr/bin:/c/windows/foo:/usr/local/bin:/c/windows/bar
~$ path=(${(M)path:#/c/windows/*} ${path:#/c/windows/*})
~$ echo $PATH
/c/windows/foo:/c/windows/bar:/usr/bin:/usr/local/bin


--
Stéphane





[ Post a follow-up to this message ]



    Re: Suggestion please : adjust the order of pathes in $PATH  
doronve


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:50 PM

why don't you just add the local cygwin variable before any other one
cygpath=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin.... (you can put
here whatever you want)
export PATH=$cygpath:$PATH
then you'll skip all the manipulation of the path - quick and dirty ;-)






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:39 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register