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.

The title says it all. I would like to type "run" in the command line and it would execute /pathtoscript/script.sh.
Thank you!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Create a file named run with the contents:

#!/bin/sh
exec /pathtoscript/script.sh "$@"

Place the file in your path and set the executable bit.

What is "your path"?

At the command line, type:

echo $PATH

You will see a colon-separated list of directories. These are the directories that the shell searches when looking for a command to run. They are collectively called the path. You will want to place your new file run in any one of those directories.

Alternate approach for interactive work

If you just want run to work when you are working interactively, you can create an alias:

alias run=/pathtoscript/script.sh

If you want this alias saved permanently, put that line in the .bashrc in your home directory.

share|improve this answer
    
What does "your path" mean? –  QuyNguyen2013 Jul 28 at 19:31
    
If I want it permanently which method should I use? –  QuyNguyen2013 Jul 28 at 19:38
1  
@Autospamfighter Both are permanent. There are times when aliases don't work, so using the run file is more robust. –  John1024 Jul 28 at 19:41
    
Thanks! I will try the "run" file. –  QuyNguyen2013 Jul 28 at 19:42
    
You forgot to do #!/bin/sh –  QuyNguyen2013 Jul 28 at 20:49

In *nix shells, the way this is done is by adding an executable file (or symbolic link to an executable file) to one of the directories listed in the PATH variable. From a hypothetical session:

$ which foo
which: no foo in (/usr/local/sbin:/usr/local/bin:/usr/bin)
$ foo
bash: foo: command not found
$ echo "$PATH"
/usr/local/sbin:/usr/local/bin:/usr/bin
$ sudo ln -s /path/to/my/script /usr/local/bin/foo
$ foo
[whatever your script prints]
share|improve this answer
    
Is the *nix shell standard? Do I need to install anything? –  QuyNguyen2013 Jul 28 at 19:36
    
"*nix" is just a historical shorthand for "Unix-like". It's not something you have to install. –  l0b0 Jul 28 at 19:44

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.