This is nothing new but yet I thought why not document it so that its etched into my memory (Ya I know I am selfish )
When you run a command or try executing a shell script, the shell first tries to look if your script is found in the Current Directory. To execute a shell script you should be in the same directory where it was created/written.
Now this isn’t possible always – so what to do? There are two ways:
Method 1 -
When you are executing the script, give the full path to the script!
Now if you go by the usual file/folder structure in most of the software engineers – you can go crazy with the paths – the depth at which the script is found can drive you insane
So thankfully we have another way
Method 2 -
Add the folder of your script to the PATH variable. What I suggest is create a folder for all your scripts – say myScripts and then add this to your PATH variable.
If you are new to using the PATH variable, I suggest you go through this link on PATH variables
So here is how the shell looks for its script to execute: ( I created a small illustration of the same )
Hope this helps!!!
Comments