How to add to the search path - bin?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to add to the search path - bin?
# 1  
Old 05-15-2014
How to add to the search path - bin?

Hi,
Now I have: /Users/okn/bin for my private shell scripts.

How do I add /Users/okn/bin to my PATH?

The PATH is right now:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

The .bash_profile doesn't state anything about a PATH (yet).

I read about this:
Code:
PATH=/bin:$PATH

export PATH

or
Code:
PATH=$PATH\:/dir/path ; export PATH

What should I write into the .bash_profile?
I'm afraid I could harm the OS.

with best regards,
Omar K N
Stockholm, Sweden
# 2  
Old 05-15-2014
You haven't said which OS you are on, but i suppose it is some kind of Linux.

Notice, that there are two files: /etc/profile and/or /etc/bash.bashrc. These are systemwide settings and changing these will alter your system, so stay away from them as long as you are not sure what you do and how you do it.

Then there is "/your/home/.profile" and "/your/home/.bashrc". These files are only executed by you and you can - more or less - do whatever you want with them. The worst you might do is make login or execution of the shell for yourself impossible - log on as root, remove the offending files or replace them with some backup copy and you are again ready to go. You might want to create a separate "test user" for that purpose and experiment with the startup files for this account. Once you are satisfied you copy the files from there to your own home and use them.

Now to your initial question: "$PATH" is a list of directories, separated by colons (":") which are searched for executable files if no complete path is entered. A common PATH variable might look similar to this:

Code:
# echo $PATH
/bin:/usr/bin:/usr/sbin:/usr/local/bin

If you now enter "command" at the command line these directories are searched in the order they appear in this variable for a file which is executable and named "command": first "/bin/command", then "/usr/bin/command", etc..

Once such a file is found, it is executed. By changing the order within "$PATH" you can influence which executable (if there are several named identically) is executed. If you put "/your/home/bin" in front of your PATH by executing

Code:
PATH=/your/home/bin:$PATH

an executable named i.e. "/your/home/bin/cp" would "override" (take precedence over) the system command "cp", usually located in "/usr/bin/cp".

This is sometimes a wanted effect, sometimes not. You decide what you want here. You just need to know that writing "$PATH" is like typing the complete current value of the PATH variable, therefore, taking the above mentioned value as example:

Code:
# echo $PATH
/bin:/usr/bin:/usr/sbin:/usr/local/bin
# PATH=$PATH:/some/new/dir
# echo $PATH
/bin:/usr/bin:/usr/sbin:/usr/local/bin:/some/new/dir
# PATH=/other/dir:$PATH
# echo $PATH
/other/dir:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/some/new/dir

etc..

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Php search path

Probably simple, but I don't see it. jack@veritron /u/email $ cat p3.php <?php require_once './lib/swift_required.php'; $x=get_include_path(); echo "$x \n"; set_include_path('./lib:./lib/classes:'.$x); $x=get_include_path(); echo "$x \n"; $transport =... (1 Reply)
Discussion started by: jgt
1 Replies

2. Programming

Gcc linker search path order

I have a build where I wish to link against and load a specific version of a library and a different version of the same library is installed on the system. I'm using a -L option to point to the version that I wish to link against but gcc still seems to choose the installed version. Is there a way... (4 Replies)
Discussion started by: Richard Johnson
4 Replies

3. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

4. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

5. Shell Programming and Scripting

PATH dircetory search order

Hello I using CygWin and am working on project that requires whereby after I make some code changes and rebuild I have to manually copy the updated files into the install directory to test them. There is a build output directory where these files placed, but the program will not run from there.... (4 Replies)
Discussion started by: bobban
4 Replies

6. UNIX for Dummies Questions & Answers

extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)

Hi, I need to make some extraction . with the following input to get the right output. input: /etc/exp/home/bin ====> output: exp and input: aex1234 ===> output: ex Thanks for your help, (4 Replies)
Discussion started by: yeclota
4 Replies

7. Windows & DOS: Issues & Discussions

Path of Recycle Bin on Windows

hello everybody, I am trying to find the path of the Recycle Bin. I know that it's a temporary storage place, but it should have a path that we can refer to. I want to know it because I sometimes use cygwin to work on Windows, and when you delete something with it, it's gone. I just checked... (4 Replies)
Discussion started by: milhan
4 Replies

8. Shell Programming and Scripting

add bin to variable PATH and save changes

i wrote a script and is running. I add the path bin to variable PATH, i.e. PATH=$PATH/bin. i add this to PATH in order to run the script in any path working directory. Thats ok. The problem is as son as i close the session and start a new session, changes are lost. How can i tell the shell or... (1 Reply)
Discussion started by: alexcol
1 Replies

9. UNIX for Advanced & Expert Users

set path so all new users can execute the command in /bin/mycommands

I want to add a default path /bin/mycommands along with others to be loaded as default path for all new accounts created on my system . With out the new accounts not having to change thie manually to /bin/mycommands.Do I change the /etc/profile ? is there any better way? Please throw some... (2 Replies)
Discussion started by: sravusa
2 Replies

10. UNIX for Dummies Questions & Answers

home directory in search path

Is it unsafe to put your own home directory (a regular user) in your search path? I am writing useful shell scripts, but don't have the permissions to put them in /usr/bin. (Korn shell) thanks (2 Replies)
Discussion started by: jpprial
2 Replies
Login or Register to Ask a Question