Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've just installed a new program (let's call it foo) on my Linux machine. The program's files are in an unusual location that is not currently part of my $PATH. If I would like to be able to easily run this program from terminal, while in any directory, is it better to change my $PATH variable or to create an alias? Does it matter?

For example, the alias method would be adding this: alias foo="/path/to/program/foo.sh"

And the $PATH method would be: export PATH=/path/to/program;$PATH

Which is better and why?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

"Better" is a somewhat nebulous term, but I'd recommend adding the program's directory to $PATH, because (unlike aliases) that will be inherited by subprocesses of your shell.

For example, if you start an editor from your shell and then want to run foo.sh from within the editor, as for example to compile the file you're editing or transform its text, then the editor will know where to find foo.sh; if you instead add an alias, you'd need to specify the full path to foo.sh when running it from the editor.

share|improve this answer

There is a third option. Create a link from one of the directories in $PATH to the program. A new directory can be dedicated just for this purpose (to link to programs in non standard locations). This way PATH will not be polluted if there are more programs like this added in the future and also Aaron mentions, it won't depend on the alias where the alias is not available.

share|improve this answer

Absolute path (Here your alias) is more and more faster than set PATH variable..

Because when you set PATH variable for example "/path/to/program" and you want to execute foo.sh shell look at PATH variable and then search foo.sh in that directory (/path/to/program) but when you use absolute path (Here your foo variable), shell won't look at path and then search that directory (/path/to/program) to find "foo.sh".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.