when we run a normal command we just type the name of it but why we use ./ instead of just typing its name when running the script?
Asked
Active
Viewed 72 times
1 Answers
3
When you run a shellscript or some other program that is in the current directory, you use
./scriptname
because .
denotes the current directory.
When a shellscript or some other program is in a directory in PATH, it is enough with its name for the system to find it,
program-in-path
You can watch PATH with
echo $PATH
You can put own programs into ~/bin
(create your own 'bin' and put your own programs there) and it will be found by you, or put it into /usr/local/bin
and it will be found by all users.

sudodus
- 46,324
- 5
- 88
- 152
.
into the$PATH
so you never have to type./
again, not in any directory. However, that is a security vulnerability (someone could write a malicious program calledls
and put it in your favourite path, where it was just waiting for you to execute it) so don't do that. – Jos Jun 08 '21 at 18:01