One of the most important environment variables on Linux operating systems is the PATH variable. This variable holds the colon-separated list of directories used to find commands that you type. For example, if PATH is set to “/bin:/usr/sbin” and you type echo, Linux looks for an executable program called echo in /bin and then in /usr/sbin.
For example, lets say that we have a script called script.sh and we want to execute it. If the script is placed in the folder listed in the PATH variable, we can run the script no matter what directory we are in:
In the example above you can see that, although our working directory is /home/bob, we were able to execute a script called script.sh. This is because the script is located in the /bin directory, the directory listed in the PATH variable. But what if we move the script to the other location, not listed in the PATH variable?
From the output above you can see that, although our working directory is /home/bob, the directory in which the script script.sh is located, we can’t execute it. This is because the system checks for commands only in directories listed in the PATH variable.
Post a Comment