3

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

2 Answers 2

2

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.

1
  • 1
    @Autospamfighter Both are permanent. There are times when aliases don't work, so using the run file is more robust.
    – John1024
    Jul 28, 2014 at 19:41
2

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]
1
  • "*nix" is just a historical shorthand for "Unix-like". It's not something you have to install.
    – l0b0
    Jul 28, 2014 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .