@user-123:~$ Downloads/execfile-3.4/execfile
@user-123:~$
@user-123:~$ cd Downloads/execfileparentdir-3.4/
@user-123:~/Downloads/execfileparentdir-3.4$ execfile
execfile: command not found
@user-123:~/Downloads/execfileparentdir-3.4$ ./execfile
@user-123:~/Downloads/execfileparentdir-3.4$
What's exactly the reason of using ./
behind execfile
?
Note that I'm not asking about the functionality of ./
. In other words, I wanted to know why in order to run an executable file from terminal it requires the address from current directory to the given file? Why when we are in current directory like the way that the terminal behaves in other cases behave and just recognize the file name automatically so that we run it by just typing the file name instead of putting and ./
behind it?
Edit:
One reason might be the security and preventing the user to accidentally execute another (probably malicious) file. That however is a very credible reason to do so but aren't they sacrificing the consistency of a rule for the sake it? And aren't other ways to handle this problem and not make an exception in a unified rule (the prediction of the file names in current dir)? This may sound like a trivial exchange but I want to be sure if it's the tiniest one.
$PATH
works? Is your question simply "why is the current directory not added to$PATH
by default"? You seem to be confusing filename expansion with the$PATH
variable. Filename expansion works just fine, there is no exception here. – terdon Dec 13 '18 at 19:41cat README
,cat
looks forREADME
in the current directory. … (Cont’d) – G-Man Says 'Reinstate Monica' Dec 14 '18 at 02:56#include <stdio.h>
in a C program, the C compiler looks for/usr/include/stdio.h
.) But the shell, after eliminatingcat
as a builtin or a keyword, looks for it in/bin
and the other directories specified byPATH
. If the "unified rule" that you're talking about actually existed, you'd always have to type/bin/cat
,/bin/cp
,/bin/ls
, etc. – G-Man Says 'Reinstate Monica' Dec 14 '18 at 02:56