Why you can’t just enter a command that’s in the current directory
Guy on a mailing list explains that he downloaded & compiled a program & then tries to run the program when he runs into a problem. Like this:
Guy wants to know why this is happening & why he can’t run the program directly, & proposes putting a .
(indicating the current directory) in his PATH
. David Dooling1, a member of the list, gave a great explanation as to what was going on & why:
It is a security issue. If you have
.
(the current directory) in your path and youcd
into my home directory where I have a script namedls
with the contentsrm -rf $HOME
, I could trick you into inadvertently deleting your home directory. To mitigate this, some people put.
last in thePATH
. But then I could just create a script namessl
and hope you mistype. It is safest to not have it in thePATH
and explicitly run./command
when you want to run things in the current directory.
David’s explanation is right on. Just put a ./
in front of any command that you want to run in your current directory, & things will work well.
-
David gave me permission to post his comment here. ↩