Hello, friends. In this post, you will learn How to run scripts without typing the full path? So, you can use these scripts as commands from a terminal or launcher.
When making a bash script with some automation instructions, we have to run it from the terminal as follows
Or as follows
In this sense, we always have to locate the full path of this script to execute it. However, there is a way to make this script run as a system command.
This is so that you can use it from anywhere in the prompt, or even from system launchers.
How to run scripts without typing the full path
The solution is simple and is solved by creating a symbolic link to a directory that is in the PATH.
To find out what directories are in the PATH, run
And you will get an output screen like this:
Normally, you would make the symbolic link to any of these locations, with
/usr/local/bin being the most recommended options.
So, the procedure is easy thanks to the ln command.
sudo ln -s /full/path/to/your/shfile /usr/local/bin/name
name will be how you want the command line to run. For example,
sudo ln -s ~/test.sh /usr/local/bin/test
The result will be that when you run
It will actually run the script
In this simple way, you can run scripts without typing the full path.
A good practice is to create a specific directory for the scripts and then add it to the PATH.
This will avoid mixing scripts with binaries in the system directories. You will also have control over the scripts that will be in the PATH.
This short but useful post, helped you to make the bash scripts that you make, can quickly be added to the PATH, so you can run it without knowing the entire path.