I am executing a .sh script today. It is executed with prefix "./.sh,I am a bit confuse because it is also executed without ./.but why this is required to use ./
Could you please explain me that why ./ is used to run .sh scripts?
The ./
is needed to tell bash interpreter where the script is located. There is a fixed set of directories that bash interpreter will check to run a command.
If your script is not in one of these directories than it will not find you script unless you specify the path. The ./
is telling the bash interpreter that the script is in the current directory.
You could also run the script from any other directory by using the full path.
e.g. ./script.sh
from within /path/to
is the same as running /path/to/script.sh
from anywhere if the script is located in /path/to
.
You can run echo $PATH
to get a list of all the directories the bash interpreter will check. If you move you script or place a symbolic link in one the directories you will be able to execute it just using the file name script
.
Using "./", means that you ask your file to be runned. But, your file has to be executable, else it will not work.
If your file is not executable, you will have to prefix your command with the program intended to run it. For your sh script, it will probably be : "/bin/sh myscript.sh" .
$PATH
../
before executing a program in the current directory?