Path variable in Linux?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Path variable in Linux?
# 1  
Path variable in Linux?

Hi guys,

In Windows, whenever I want a execute a program using just a relative path on the command prompt, I simply edit the 'Path' variable and append my parent directory.

Is there something like this available in Unix? I have a binary for Virtualbox called VBoxManage that I want to execute without tying the absolute path (i.e. not /usr/lib/virtualbox/VBoxManage) and instead just relative (VBoxManage). The binary is located in /usr/lib/virtualbox.
# 2  
yes, there is such environment variable, its called PATH, you can set/modify it with 'export' command. but, iirc, that would affect only current bash.
edit ~/.bashrc to set it for user.
# 3  
Additionally, Windows uses ";" as a delimiter:

Code:
Path=\first\path;\second\path;...

whereas Unix uses ":":

Code:
PATH=/first/path:/second/path:...

I hope this helps.

bakunin
# 4  
You can append this directory to existing PATH variable using

Code:
export PATH=$PATH:/usr/lib/virtualbox/VBoxManage

and probably add this line to your .profile file so that this gets set every time you login.
# 5  
Create a file .profile that adds the desired path!
You can do that in a text editor, or by the following commands:
Code:
cd; touch .profile
grep /usr/lib/virtualbox .profile || echo 'PATH=${PATH}:/usr/lib/virtualbox; export PATH' >> .profile

Verify the result:
Code:
cat .profile

# 6  
Not quite.

The .profile is not the right place to put a PATH variable. ~/.profile is executed exactly once: when a user logs in (actually it is started by the login process). But perhaps you want to set the PATH variable anew each time you start a new shell, not once in your session, don't you? For this you have to put the PATH into the rc-file of the shell, depending on which shell you use this would be ~/.kshrc, ~/.cshrc, ~/.bashrc or a similar file.

I hope this helps.

bakunin
# 7  
Quote:
Originally Posted by bakunin
Not quite.

The .profile is not the right place to put a PATH variable. ~/.profile is executed exactly once: when a user logs in (actually it is started by the login process). But perhaps you want to set the PATH variable anew each time you start a new shell, not once in your session, don't you? For this you have to put the PATH into the rc-file of the shell, depending on which shell you use this would be ~/.kshrc, ~/.cshrc, ~/.bashrc or a similar file.

I hope this helps.

bakunin
No,
.profile is enough. A new shell will inherit environment (including PATH) from its parent i.e. the login shell.
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #346
Difficulty: Easy
AWK was created at Bell Labs in the 1960s,
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to concatenate Path name to a variable??

I have the path name in a Variable Ex: $XML_PATH_FLAG = /ebs/appl/u00/universe01/inbound/universeorders Now I have to pick up ALL XML files in this directory . In other words I have to pick up ALL the files /ebs/appl/u00/universe01/inbound/universeorders/F1.xml... (2 Replies)
Discussion started by: Pete.kriya
2 Replies

2. Ubuntu

PATH environment variable

PATH is an environment variable. When I open a terminal say terminal 1 and set some path in PATH variable it gets set which I can see using ech $PATH. But when I open a new terminal say terminal 2 and fire echo $PATH why cannot I see the same output as seen in terminal terminal 1? Why the path... (4 Replies)
Discussion started by: rupeshkp728
4 Replies

3. Shell Programming and Scripting

Path a variable to sed that includes a path

Hi I'm trying to select text between two lines, I'm using sed to to this, but I need to pass variables to it. For example start="BEGIN /home/mavkoup/data" end="END" sed -n -e '/${start}/,/${end}/g' doesn't work. I've tried double quotes as well. I think there's a problem with the / in the... (4 Replies)
Discussion started by: mavkoup
4 Replies

4. Shell Programming and Scripting

Appending a path in user's PATH variable

Hello Folks, I want to append a path in user's PATH variable which should be available in current session. Background Numerous persons will run a utility. Aim is to add the absolute path of the utility the first time it runs so that next runs have the PATH in env & users can directly run... (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies

5. Shell Programming and Scripting

one liner to extract path from PATH variable

Hi, Could anyone help me in writing a single line code by either using (sed, awk, perl or whatever) to extract a specific path from the PATH environment variable? for eg: suppose the PATH is being set as follows PATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/bin/java:/usr/bin/perl3.4 ... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. Shell Programming and Scripting

remove a path from PATH environment variable

Hi I need a script which will remove a path from PATH environment variable. For example $echo PATH /usr/local/bin:/usr/bin:test/rmve:/usr/games $echo rmv test/rmve Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Discussion started by: madhu84
9 Replies

7. Shell Programming and Scripting

Variable directory name in path

I need to write a login script for multiple computers, however, one of the directories in question will have a different name from computer to computer. ~/Library/Application\ Support/Firefox/Profiles/<unique filename>.default/myfile For the directory named <unique filename>.default , I... (2 Replies)
Discussion started by: glev2005
2 Replies

8. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

9. Shell Programming and Scripting

Getting the path from a variable

Hi, I am having a variable Like line="/dir1/dir2/gr3/file.ksh" I need to get the /dir1/dir2/gr3 alone. the no of directories may differ at each time. Please advice. thanks in advance. (3 Replies)
Discussion started by: vanathi
3 Replies

10. UNIX for Dummies Questions & Answers

set variable PATH

Hi, i know that this topic discussed for many times but although i had researched them i couldnt succeed in my problem. i am following a step-by-step instruction guide and must do the following: ------------- To ensure access, set the path PATH $ORACLE_HOME/perl/bin:$PATH and set the Perl... (2 Replies)
Discussion started by: merope
2 Replies

Featured Tech Videos