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.

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.

Additionally, Windows uses ";" as a delimiter:

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

whereas Unix uses ":":

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

I hope this helps.

bakunin

You can append this directory to existing PATH variable using

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.

Create a file .profile that adds the desired path!
You can do that in a text editor, or by the following commands:

cd; touch .profile
grep /usr/lib/virtualbox .profile || echo 'PATH=${PATH}:/usr/lib/virtualbox; export PATH' >> .profile

Verify the result:

cat .profile

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.