Adding a directory to the PATH variable
By default, there are a lot of different directories which are present in this variable, we can also add our own directory into the PATH variable which will enable us to run our script or command from anywhere in the system. This definitely saves a lot of time and effort. There are two ways in which we can add to PATH:
- By appending (This adds our path at the end of the PATH variable)
- By prepending (This adds our path at the beginning of the PATH variable)
Now we have to attach the /home/mukul/bin to the path, use the below command:
export PATH = $PATH: /home/mukul/bin (appending)
export PATH = /home/mukul/bin :$PATH (prepending)
Now we can run our “Sample.sh” script from anywhere and that too without any path or “./” mentions.
Note: Make sure to give permission to your file, or else it will give an error.
chmod +x Sample.sh
You have misspelled the command:
We all make mistakes and that is a natural thing, this error can also arise when we type the command incorrectly.
For example, If we type PQD instead of PWD we will get this error.
So, these were the four ways in which you can get rid of the Bash: Command Not Found Error in Linux.
How to fix Bash: Command Not Found Error in Linux
The “command not found” error is a frequently encountered issue in Linux systems. This error occurs when the system is unable to locate the file specified in the path variable.