|
Home > Archive > Unix Shell > March 2006 > Suggestion please : adjust the order of pathes in $PATH
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Suggestion please : adjust the order of pathes in $PATH
|
|
| linq936@hotmail.com 2006-03-15, 5: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
| |
| Kurt Swanson 2006-03-15, 5: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
| |
| Chris F.A. Johnson 2006-03-15, 5: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
| |
| linq936@hotmail.com 2006-03-16, 7:50 am |
| 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.
| |
| Chris F.A. Johnson 2006-03-16, 7:50 am |
| 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
| |
| Kurt Swanson 2006-03-16, 7:50 am |
| 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
| |
| Stephane CHAZELAS 2006-03-16, 7:50 am |
| 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
| |
| doronve 2006-03-16, 7:50 am |
| 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 ;-)
|
|
|
|
|