Hi Guys,
Hope you are doing well out there.
Can you please let me know why do we use "./" to run a shell script?
Is it to run the script in the current shell or something else?
What if I have already defined a bang in the script say #!/bin/ksh and then running the script as ./myscript?
I would also like to know the difference in running a script as ./myscript and . /myscript(with white space).
Any help from you in understanding this would be highly appereciated.
Thanks,
Chandan
./ means you are specifying the path (location) of script.
it means the shell will execute the script from the current pwd.
Its same if you give complete path like /home/amit/myscript.sh
else if you are in the /home/amit/ -- then ./myscript.sh
1 Like
It executes a script that is in the current directory instead of where it belongs, which is in a directory in your $PATH.
The shebang tells the OS (or your shell) what interpreter to use to run the script.
./myscript is described above.
. /myscript will attempt to source (not execute) a script located in /, the root directory, where it should never be.
1 Like