The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
grep unix.com with google



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
How does the PATH environmental variable work?

Hello.

I have a question about how the PATH environment variable works.
I wrote a script in $HOME/bin/gvim.
I want it to be called instead of /usr/bin/gvim,
so I've placed it before in the PATH.

However, it is still the old one that is found.
If I open an other terminal, I have the desired effect: the script in $HOME/bin is found


I don't understand how it's possible to have two terminals where the PATH variable is the same, echo $PATH outputs the same thing, but the two don't find the same script.
Could anyone explain me the subtlety I'm missing here?
Thanks in advance.
  #2 (permalink)  
Old 11-27-2009
vidyadhar85's Avatar
Moderator(The Tutor)
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,453
after changing the PATH did you re ran the .profile??
if not run it (. .profile) then you will get the desired result..
  #3 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
Quote:
Originally Posted by vidyadhar85 View Post
after changing the PATH did you re ran the .profile??
if not run it (. .profile) then you will get the desired result..
Thanks for the reply.
Sourcing the .profile did make the difference.

Why do I need to re-run the .profile?
  #4 (permalink)  
Old 11-27-2009
vidyadhar85's Avatar
Moderator(The Tutor)
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,453
because this will be written inside .profile

Code:
export PATH

after changing the PATH just by exporting also you can see the result no need to source the full .profile :-)
  #5 (permalink)  
Old 11-27-2009
Registered User
 

Join Date: Nov 2009
Posts: 3
Thanks again for help

Now I know how I came up with two terminals with the PATH, but not the same call
Here is what happened.

I created a script in $HOME/bin/gvim

It was not executable (forgot to chmod +x), but there is another farther in the PATH

I call once gvim. I skips the one not executable, calls the second one.

I changed with 'chmod +x' the first one.

Surprisingly, it still skips the first one, and calls the second one. Except if I open another terminal.
  #6 (permalink)  
Old 11-28-2009
Registered User
 

Join Date: Nov 2009
Posts: 1
Strange. On a hunch, try hash -l. You set your new path without logging out, but a new shell works like you want. It the old path is hashed, it will take precedence.
  #7 (permalink)  
Old 11-28-2009
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,146
A lot of shells cache the results of a PATH search so that they do not continually rescan all of the directories on the PATH looking for stuff. Most of the time this speeds stuff up nicely. But sometimes those caches become a pain. My solution, which I admit is extreme, is to restart the shell. So say I'm running ksh. I do this:
exec ksh
This causes the shell to replace itself with a new copy. ksh calls this particular feature "tracked aliases" and I think that "unalias gvim" would work, but I actually never have tried it. I just restart the whole shell.
Sponsored Links
Reply

Bookmarks

Tags
path of running script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove a path from PATH environment variable madhu84 Shell Programming and Scripting 9 10-23-2009 04:02 AM
Conditional Compilation based on Environmental Variable in Unix BrighterLater High Level Programming 2 05-07-2009 01:07 PM
setting ksh environmental variable mefquik Shell Programming and Scripting 2 03-21-2009 12:51 PM
Environmental Variable janemary.a Shell Programming and Scripting 2 05-15-2007 02:46 AM
Set Oracle Environmental Variable !! uuser Shell Programming and Scripting 4 02-22-2006 02:46 PM



All times are GMT -4. The time now is 07:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0