Linux + run some script without “./” + alias

linux

I have a Linux machine and I have a script called load_info and the script is located in /var

I would like to be able to run the load_info script from another directory without having to prefix the command with "./"

For example if I was in /root I want to be able to type load_info (without ./) and have this execute the /var/load_info script.

So how do I make it so that if I cd /root, I can type load_info and have it run the /var/load_info script.

Best Answer

Your shell will search the paths listed in the $PATH environment variable for the typed command if it's not fully qualified (e. g. vi instead of /usr/bin/vi). You can easily add another path to your $PATH variable by appending a line in your ~/.profile or ~/.bashrc:

export PATH="$PATH:/path/to/your/scripts"

As kind of best practice you should also save your script under /usr/local/bin or /usr/local/sbin, see hier(7).