The PATH environment variable contains a list of folder paths in
which to look for executables:
echo $PATH/__w/rust/rust/node_modules/.bin:/__w/rust/rust/notebooks/node_modules/.bin:/__w/rust/rust/node_modules/.bin:/__w/rust/node_modules/.bin:/__w/node_modules/.bin:/node_modules/.bin:/usr/share/nodejs/@npmcli/run-script/lib/node-gyp-bin:/__w/rust/rust/venv/bin:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
If an application we want to run has not its folder listed inside
PATH, we cannot run it, unless we specify the path to find it.
In order to show an example, we will create a shell script and put inside a subfolder.
Here is the creation of the sub-folder:
mkdir -p my/sub/folderAnd the script creation:
We now make the script executable:
chmod u+x my/sub/folder/a_script.shThe script is in the following location:
exa -T mybash: exa: command not found
And its content is correct:
bat my/sub/folder/a_script.shHowever, if we try to run it by its name, the shell complains that it cannot find it:
a_script.shThis is because the shell does not know where to find the script. We can only run it if we specify explicitly the path to find it:
my/sub/folder/a_script.shTo make it findable by the shell, we need to add its folder to the
PATH variable:
PATH="$PATH:my/sub/folder"Then, by looking in each folder of the PATH environment variable,
the shell is able to find the script:
a_script.shUnfortunately, the modification of the PATH we have just done is
only valid for the current shell session. If we open a new
session, we will have to do the same modification again.
To avoid this, we need to set the PATH modification inside the
$HOME/.bash_profile configuration file for bash.
Edit or create the file $HOME/.bash_profile and append the
following line:
PATH="$PATH:my/sub/folder"The next time we log in, the file will be read and the PATH
modified.
For now, we only have to source the file explicitly in order to
get the modification:
source $HOME/.bash_profile