because if the script is in a folder not contained in the PATH environmet var, the script will not be found... with ./script.sh you tell to the OS to execute the shell located in the current directory. if you want to execute a shell in other folder (not in PATH) execute it with /path/to/script/script.sh
The only reason you need to use the ./ is if you don't have the directory you are working in in your path statement or if you want to execute something in the current directory rather than the one in another location in your path statemnt. Ex. if you wanted to run a script in your working directory called batch, but not /bin/batch, you would type ./batch.
It's especially a risk if you put . at the start of your path. The scenario is someone puts a file called 'ls' in some directory, then you come along and type 'ls' expecting to get a directory listing. But instead of running /bin/ls, you run the attackers script instead. Which may well run /bin/ls and hide itself in the process leaving you none the wiser. Whatever else it does it left to the imagination.
Putting . at the end of your path doesn't buy you much. All the correctly spelled commands will run what you expect to run, but faulty memory and typos will still catch you out.
At least ./script is a rather deliberate key sequence which is less likely to be typed accidentally.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.