Is there any $PATH default setting?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Is there any $PATH default setting?
# 1  
Old 09-11-2012
Is there any $PATH default setting?

This is a very newbie's question:
I was trying to add a new version of the same command "blastn", but the old command always shows up first.
Code:
which blastn
/usr/local/bin/blastn

The two versions of the same command "blastn" are located in:
Code:
which -a blastn
/usr/local/bin/blastn
/home/yifangt/download-software/bin/blastn

What I want is the one in my home directory "/home/yifangt/download-software/bin" .
I had specified the second one in my .bashrc file (and .bash_profile)
Code:
export PATH=$PATH:/home/yifangt/download-software/bin

How can get rid of the "/usr/local/bin/blastn" without removing the whole directory?
I can't remove the blastn in "/usr/local/bin" because it is preferred by other people, and many other commands sit in that directory too.
I had thought the my local .bashrc will overwrite the old $PATH so that "/home/yifangt/blastn" should be the one I use. Did I miss anything?
Thanks a lot!
# 2  
Old 09-11-2012
Directories in PATH are searched in the order they appear. If you want your bin directory to take precedence, it has to occur ahead of the directory containing the conflicting executable.

Alternatively, if the issue is only with this one binary, you could create an alias with an absolute path and leave PATH unmodified:
Code:
alias blastn=/home/yifangt/download-software/bin/blastn


Regards,
Alister
This User Gave Thanks to alister For This Post:
# 3  
Old 09-11-2012
Thanks alister!
I should have thought about the alias!
Actually the /usr/local/bin is the place where many shared commands are put in by the admin, but all my corresponding commands are put in my local ~/download-software/bin, most of which I update frequently by myself. How give this directory precedence over /usr/local/bin? Is that simply put
Code:
export PATH=$PATH:~/download-software/bin

at the beginning in .bashrc file? Thanks again!
# 4  
Old 09-11-2012
Quote:
Originally Posted by yifangt
Thanks alister!
I should have thought about the alias!
Actually the /usr/local/bin is the place where many shared commands are put in by the admin, but all my corresponding commands are put in my local ~/download-software/bin, most of which I update frequently by myself. How give this directory precedence over /usr/local/bin? Is that simply put
Code:
export PATH=$PATH:~/download-software/bin

at the beginning in .bashrc file? Thanks again!
Almost. If you want the the commands in your own bin directory to take precedence over those supplied by your system administrator, you have to put your bin directory first in your $PATH. So, you would want:
Code:
export PATH=~/download-software/bin:$PATH

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 09-12-2012
default $PATH setting

Can I ask another question related to this? From .bashrc I removed the line
Code:
export PATH=$PATH:/usr/local/bin

but /usr/local/bin is always there so I thought there is a default setting from the original system (bash shell). Is it /etc/profile?
Forgive me for this dump question, but I feel need catch a further understanding on this issue.
Thanks a lot!

Last edited by yifangt; 09-12-2012 at 01:09 PM.. Reason: typo
# 6  
Old 09-12-2012
Quote:
Originally Posted by yifangt
Is it /etc/profile?
Yes, it is. In fact, there are several files read when a session/shell starts:

Whenever a session starts (that is: a user logs in), a system profile is read. In most systems this is called "/etc/environment" (AIX) or "/etc/profile" (SunOS, Linux).

Then a user profile is read. On most systems it is called ".profile" and resides in the users "$HOME". Commonly in "~/.profile" a variable named "ENV" is set, which names the startup file for the shell.

After these two files the shell itself is started. Which one this is depends on the user entry in the file "/etc/passwd", which is readable by everyone. "grep" it for you own username, which will possibly look similar to:

Code:
# grep username /etc/passwd
username:x:1001:1001:username,,,,:/home/username:/bin/ksh

The last entry is the path the shells executable, in this case Korn shell.

The following part of the process is executed every time a shell starts. This is the case for every log-in-process, because as the last stage of the log-in a shell is started, but also when a script is started with a shebang ("#!") in the first line, you enter "ksh" ("bash", ...) on the command line, etc..

First, the shell reads a system-dependant startup-file. In linux (and with bash) this is "/etc/bashrc", other system/shell-combinations may have different startup files. A look in the man page of your shell will tell you which one it is.

Second, a user-dependant startup file is read. This is either the file declared via the "ENV" variable (see above) or a default file: for bash it is "~/.bashrc", for ksh it is "~/.kshrc", etc.

Every later file can override settings from an earlier run file. Because i don't like all these graphical gimmicks like coloured ls-output my startup-files on Linux systems usually are full with commands unsetting the "helpful" aliases and other fancinesses the "/etc/profile" is setting. This may seem inefficient (first setting a lot of things, than reset all these setting to zero), but i don't like to change the "original" look and feel of the Linux systems by changing the system-wide settings. This way it is only my own account which behaves like i think a Unix-account should behave.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting class path

hi , can anybody help me to chage the class path in unix server.. what are the files need to update .... (2 Replies)
Discussion started by: Madhu Siddula
2 Replies

2. UNIX for Dummies Questions & Answers

Setting up a private path

Hi all, This is probably a very simple question but I couldn't even think of how to phrase it intelligently so google could tell me the answer. Basically I am a user on a server, I am not the admin and do not have root privileges. I have downloaded a bunch of programs that I need to use and... (2 Replies)
Discussion started by: DavyK1984
2 Replies

3. Shell Programming and Scripting

Setting path names

I am in a directory called /abstracts Doing tree -d gives . ├── geo1936 │ ├── geo01n01 │ ├── geo01n02 │ └── geo01n03 ├── geo1937 │ ├── geo02n01 │ ├── geo02n02 │ ├── geo02n03 │ └── geo02n04 (4 Replies)
Discussion started by: kristinu
4 Replies

4. Solaris

Setting PATH - Vanishes

Hi , I new to solaris. I want to set path variable . Eg: JAVA_HOME. When i do this, #JAVA_HOME=/usr/jdk/jdk1.6 #export JAVA_HOME #echo $JAVA_HOME /usr/jdk/jdk1.6 Then its ok. When i toggle to bourne shell or if i log off or restart. then JAVA_HOME is echoed blank. How to set... (4 Replies)
Discussion started by: gnanagurus
4 Replies

5. Shell Programming and Scripting

Setting up a path in UNIX

I have the following script "test". When i tried to execute it, I am not able to run it. I dunno why ? Then i tried getting the first few lines of the script which is displayed below: $head -10 test #!/bin/ksh PROG=$0;export PROG ORAUSER=`get_inf_env INFORM_DB_ACCOUNT`;export ORAUSER... (13 Replies)
Discussion started by: bobby1015
13 Replies

6. Solaris

Problem Setting $PATH

I am trying to install the pkg-get package to a fresh install of Solaris 10. I am able to download and install correctly using the default directory for both pkg-get and wget as found on blastwave.org. When I issue the command "which wget and which pkg-get" it returns no wget or pkg-get found in... (1 Reply)
Discussion started by: greengrass
1 Replies

7. Shell Programming and Scripting

Setting path

Hi all, I have a java command in a shell script. When i m executing the command from the prompt its working fine. But when i paste the same command in a shell script and execute the shell script it says path not found. Please help. (5 Replies)
Discussion started by: radhika03
5 Replies

8. UNIX for Dummies Questions & Answers

Help on setting path variable

Hi there, I need help on setting the path variable. How can I set the path variable with Bourne Shell. My scripts goes like this, but did not work. #!/bin/sh PATH=/usr/bin:/usr/ucb:/etc:/export/home/zchen/home export PATH Thanks, Z (4 Replies)
Discussion started by: randomcz
4 Replies

9. UNIX for Dummies Questions & Answers

Setting $PATH for a particular file...????

:) dear members; I am trying to placea directory to keep minor records in particular directories.. rather than just rely on hard links.. I would like to set the $PATH variable so that I can access the directory itself from anywhere; ex./ /tmp or /bin /var... I know how to export enviromental... (4 Replies)
Discussion started by: moxxx68
4 Replies
Login or Register to Ask a Question