VectorLinux
October 02, 2014, 04:13:09 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: how to add a path to existing path?  (Read 2750 times)
omergrigg
Member
*
Posts: 29


« on: December 09, 2009, 11:59:45 am »

Hello all,
I'd like to permanently add a certain path to the default path in VL (I use VL Lite 6).
I think I should edit /etc/rc.d/rc.local - but I'm not sure.
Which file I should edit?
What's the correct syntax?

Thanks!
Logged
bigpaws
Vectorian
****
Posts: 1850


« Reply #1 on: December 09, 2009, 12:19:53 pm »

I am not sure I understand.

A path is the route to a file. If you are trying to create
a link to a file in another location, then linking would be
what it is referred as. Here is a sight about that:

http://lowfatlinux.com/linux-link-files-ln.html

If you are trying to get something to run or start, then
using /etc/rc.d/rc.local would be the recommended place
to place it.

Bigpaws
Logged
omergrigg
Member
*
Posts: 29


« Reply #2 on: December 09, 2009, 12:25:36 pm »

What I mean is that I want to be able to launch a certain application (which sits in a certain folder) from anywhere.
it's like "addpath" in MATLAB, if this means anything.
But I want to permanently add it - so I need to edit some file that loads every boot - such as rc.local, and include the path to that application.

But I don't know which file to edit, and I don't know how/what syntax.

Thanks!
Logged
M0E-lnx
Administrator
Vectorian
*****
Posts: 3181



« Reply #3 on: December 09, 2009, 05:36:23 pm »

do
Code:
echo $PATH
in a terminal.. it will show you your path.

You should only need to edit your ~/.bashrc file if you need to modify this path for some reason.

As you can see, the path is a list of directories that you are allowed to access. THis varies on your account settings. You can clearly see that the list is separated by a ":" in between directories. Just follow the same format when appending it.
Logged

toothandnail
Tester
Vectorian
****
Posts: 2527


« Reply #4 on: December 10, 2009, 12:26:43 am »

I use a 'bin' directory to keep a number of scripts. While it is a lot more elaborate than needed, I put this into my ~/.bashrc to check whether the directory exists and, if it does, add it to the path for my normal user:

Code:
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
        PATH=~/bin:"${PATH}"
fi

paul.
Logged
roseway
Packager
Vectorite
****
Posts: 135



« Reply #5 on: December 10, 2009, 07:09:27 am »

It's not really a good idea to use .bashrc to add to your path.  ~/.bashrc is called every time you launch a bash terminal, but you probably only want to add to the path once at login time. The place to put path modifications is ~/.bash_profile.
« Last Edit: December 10, 2009, 07:13:59 am by roseway » Logged

Eric
toothandnail
Tester
Vectorian
****
Posts: 2527


« Reply #6 on: December 10, 2009, 07:31:30 am »

It's not really a good idea to use .bashrc to add to your path.  ~/.bashrc is called every time you launch a bash terminal, but you probably only want to add to the path once at login time. The place to put path modifications is ~/.bash_profile.

Smiley If you check, you will find that adding something like the code above to you ~/.bashrc will only had the directory to the path once, not multiple times.

~/.bashrc is probably the safest place to add such information. ~/.bash_profile is only executed when a login shell is started, and, if my reading is correct, ~/.profile has a very low execution priority - it is only executed if ~/.bashrc is not found.

paul.
Logged
omergrigg
Member
*
Posts: 29


« Reply #7 on: December 11, 2009, 09:15:51 am »

I found the file ".bashrc" in directory "/home/use/"
I opened it and added at the end the path that I wanted =
export PATH="default/default:default/default:/home/user/directory"
saved the file and restarted linux.
It didn't work...
Is my syntax wrong?
I tried locating the file ".bash_profile" but didn't find it

Please help!
Logged
toothandnail
Tester
Vectorian
****
Posts: 2527


« Reply #8 on: December 11, 2009, 02:41:31 pm »

I found the file ".bashrc" in directory "/home/use/"

I assume by that you mean:

Code:
/home/<your-username>
?

If so, that is where you should find it...

Quote
I opened it and added at the end the path that I wanted =
export PATH="default/default:default/default:/home/user/directory"

I'm afraid I'm not entirely clear on what you mean by that. Also, did you really surround the path you were trying to create by double quotes ("). If so, the syntax is certainly wrong, I'm afraid.

The example I showed earlier uses the normal Bash syntax for expanding a variable (the only reason there are double quotes in there). The expression "${PATH}" would expand to whatever the normal path is (something like /usr/bin:/bin:/usr/local/bin: etc.) As a result, if you use it, you will automatically add the directories already in the path to whatever new ones you specify. If you specify new directories (seperated by a colon) before the "${PATH}" variable, the new direcories will be at the front of the path. If you place the new directoreis after the :"${PATH}" variable, they will be appended to the original path. Your choice.... But you need the variable correctly stated, and you need to ensure that the the syntax is correct. Also, because your ~/.bashrc is read every time you open a terminal (other than a login terminal, which shouldn't concern you under normal circumstances), you do not need to use 'export'. My code fragment checks to see if the ~/bin directory exists before adding it to the path (as I said ealrier, more elaborate than it really needs to be). For your purposes, all you really need is something like this:

Code:
PATH="${PATH}":/<directory1>:/<directory2>/<and three>:/<directory4>

substituting the names of the directories you want to add for the names I have put in pointy braces.

Quote
saved the file and restarted linux.

Smiley Restarting is a bad habbit left over from Windows use. Most things running in a Linux system can be stopped, then restarted to take advantage of any changes made to their configuration. In the case of changes made to ~/.bashrc, simply opening another terminal window will be enough to test that it has worked. So, make your changes as I've specified above, open a new terminal window, and enter this:

Code:
echo $PATH

That will expand the PATH variable and display it on your screen, so you can check that the directories have been correctly added.

You also need to remember that Linux variables are case sensitive, so you can have a '$path' and a '$PATH', which need not be the same. Most (all?) system set variables are normally upper case, but you can set variables for your own use (in scripts) which are lowr or even (if you're really masochistic) mixed case.

Quote
It didn't work...
Is my syntax wrong?

If what you entered above is literally what you put in ~/.bashrc, yes, I'm afreaid your syntax is wrong.

Quote
I tried locating the file ".bash_profile" but didn't find it

~/.bash_profile is normally only read when you open a login shell, Terminal windows from the desktop are not normally login shells, so, other than if you need to use the expanded path from the console (CTRL-ALT-F2 - F6), you don't really need ~/.bash_profile.

~/.profile might be another candidate for modification, but I have read conflicting information about when commands placed in it are executed. It is not very often used in modern Linux distributions, so I think you can safely ignore it for what you want to do.

Quote
Please help!

I hope this has been of some help. If you are still having problems, give me a list of the diretories you need to add, and I'll show you the code you should be using.

For clarity, when entering things that you don't want formatted by the forum software, enclose it in 'code' tages (# on the icon row above the emoticons).

paul.
Logged
omergrigg
Member
*
Posts: 29


« Reply #9 on: December 14, 2009, 08:49:57 am »

Hi Toothandnail,
Thanks for the detailed explanation.
I did what you suggested ( I hope I followed your instructions correctly) but it didn't work.
Here's what I did step-by-step:
booted linux
opened terminal (konsole)
logged as su (AKA root), and then typed:
cd /home/omer/
emacs .bashrc
inside .bashrc, I found the following line:
export PATH="/usr/local/bin:/usr/bin:/usr/sbin:/bin:/opt/bin:/usr/X11/bin:/usr/local/games:/usr/games/"
Below it, , I added the following lines:
#this adds the path to NEWFOLDER to the existing path
PATH="${PATH}":/home/omer/NEWFOLDER/
I saved the file, closed emacs, closed terminal, opened terminal (I also tried rebooting...), did echo $PATH
this is what I got:
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/opt/bin:/usr/local/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/qt/bin:.

double quotes are as they appear in the file, I added nothing.  I don't know what "export" does, but I believe it defines the path, no?  Anyway - maybe there's another file that needs to be configured??
Thanks for the help, and yes - I'd appreciate it you could show me the correct code I should be using

Thanks!
Logged
omergrigg
Member
*
Posts: 29


« Reply #10 on: December 17, 2009, 12:20:09 pm »

please help guys!
Logged
M0E-lnx
Administrator
Vectorian
*****
Posts: 3181



« Reply #11 on: December 17, 2009, 12:40:53 pm »

OMG!
This question was answered within the first 3 replies if you would have followed direction correctly.
THERE IS NO NEED TO ADD ANOTHER PATH= LINE
Simply append the existing line with the path you want to add. This is your current path line:
Code:
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/bin:/opt/bin:/usr/X11/bin:/usr/local/games:/usr/games/"
And you want to add /home/omer/NEWFOLDER to your path.
so you change that PATH line to add the new value at the end.. make it look like this
Code:
PATH="/usr/local/bin:/usr/bin:/usr/sbin:/bin:/opt/bin:/usr/X11/bin:/usr/local/games:/usr/games/:/home/omer/NEWFOLDER"

You can't screw this up... it's the easiest thing.
BTW, I dont see why a n00b is using emacs for a text editor... use mc.
Another thing. if your are not logged in as user "omer" on this system, adding this path will not grant you access to that directory.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!