Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

To make scripts accessible from anywhere in the terminal, one can use the following sequence of commands:

PATH=$PATH:some_path_here
export PATH

Which includes all files at the path sent in alongside all of its subfolders. Which means from then on just typing the name of a script stored within this folder structure will execute it.

How do I export only a single file this way instead of an entire folder alongside all its subdirectories?

share|improve this question
1  
I don't know how you can export a file. But why don't you, for example move your script to a new directory (to have only that script in your dir) and add the directory to the path? –  fromnaboo Jun 21 '12 at 8:23
    
It would complicate matters in the folder structure that I have alongside decreasing overview of the system. Also I don't like living with limitations. –  Hermann Ingjaldsson Jun 21 '12 at 8:40
2  
Regarding your comments about folder structure: Note that a files in a PATH'd directory are in the PATH, but files in subdirectories (of that directory) are not automatically included in the PATH. Each directory must be individually incluede in PATH. –  Peter.O Jun 21 '12 at 10:14
add comment

3 Answers 3

up vote 7 down vote accepted

Seems alias is what you need. You can specify any word to alias and set what will be execute when you execute your word.

alias newcommand='/path/to/your/command'

You can put it in you ~/.shellrc (where shell is your shell, so for bash it will be ~/.bashrc) and it will be available after start.

For more information look here.

share|improve this answer
add comment

To explain the background for Rush's answer, export does not do anything with the executables in $PATH. export PATH simply means "I want the PATH variable to be inherited by all child processes." And what happens when you type myprogram on a prompt and press Enter is a series of lookups within the shell.

When a command is specified in BASH without a pathname (e.g. myprogram, or ls), and it isn't an alias, function, builtin or keyword, BASH searches through the directories in PATH, in order from left to right, to see whether they contain an executable of the name you typed.

$PATH, in other words, is a list of directories, which is why it can't be used for single commands (except implicitly, by putting the executable in a separate directory). You can't promote a command to a builtin or keyword, but you can create a function or alias. See the previous link for a simple explanation of their differences.

share|improve this answer
add comment

Create a symbolic link to your file, and place it in a suitable PATH'd directory, eg $HOME/bin or whatever.

ln -s "/path/to/my-file"  "$HOME/bin/my-file" 
share|improve this answer
add comment

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.