Executable Path and Shell Commands
When you use an executable script in Linux with a shebang, you can make it become a shell command! To do this, you need to place it in a PATH location. A PATH location is a special folder in your Linux filesystem, and all executables inside a PATH location can be used like commands in Linux.
There are two ways to do this:
- You can look up the existing PATH locations, find one that is to your liking, and place your executable script file there. Remember to set the executable flag with chmod +x <filename> after you move the file there.
- You can add the folder in which your script file is located to the PATH variable, and make the file a command.
Below, we will discuss both of these methods.
Using Shebang in Linux
Imagine you’re working on a Linux computer and have a recipe with instructions written in different languages. But your computer only understands English! That’s where the shebang comes in. It’s like a tiny label at the beginning of the recipe that tells your computer which “translator” to use for each language. This magic symbol, #!
, followed by the interpreter’s path, is the key to understanding and running all sorts of scripts on your system.