Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do I make a new command to run a script, for example if I type runme (from any dir) it will run /run/me/script.sh? Seems simple but I can find anywhere that explains how to do this :/

share|improve this question

2 Answers 2

up vote 2 down vote accepted

simply add /run/me to your PATH, any script put there could be simply run from any directory

how to PATH from troubleshooters.com
To add directory /data/myscripts to the beginning of the $PATH environment variable, use the following:

PATH=/data/myscripts:$PATH

To add that directory to the end of the path, use the following command:

PATH=$PATH:/data/myscripts

finally

export PATH

to have it everywhere, all the times, for your user only, add these in place the lines in that user's .bash_profile file
all users except root: add to /etc/profile
for root: only possible by root's .bash_profile


my idea for the sake of laziness (not your case of running 'every' script though): add a symbolic link from a single script there to your /home/usr/loca/bin

share|improve this answer
    
:) thanks that's what I needed –  King Mar 25 '12 at 1:49

Two possiblities:

  1. alias runme='/run/me/script.sh' at the bash command prompt. This works for this session only. Put this line in ~/.bashrc if you want this change to be persistent.

  2. rename script.sh to runme and add /run/me to the PATH

http://nixcraft.com/shell-scripting/4490-how-can-i-set-path-bash-shell.html#post7234

P.S.: Make sure script.sh has executable rights (chmod +x script.sh)

share|improve this answer
    
Huh? I need it run from any directory.. My friend has stuff installed on the server in /usr/local/svn/usr/local/bin/ which I run scripts from by typing a_script_in_that_dir , but that is not my home dir, I tried putting a script into there to see if it would work but it didn't :/ –  King Mar 25 '12 at 1:01
    
If you type echo $PATH from the command line you will see all the directories (such as /usr/local/) that the shell looks for programs in. That is one method (#2 above). The other method addresses naming a script one thing, but calling it from the command line as another (aliasing) –  Huckle Mar 25 '12 at 4:25

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.