I found that sometime I use the
command to run a command, but sometime I use the
./command to run another command.
What is the difference?
xx searches the directories listed in the
PATH environment variable for a file called
xx. The first executable it finds (whether a binary or a script), it executes. It does not look in the current directory, unless
. is listed in
PATH, which is not recommended.
./xx runs the file called
xx that is located in the current directory, if there is an executable file with that name there.
To run a file by specifying its location, you must include a
/ symbol. If there is no
/ in the command (actually, the first word of the command, which is what identifies the name of the file to be executed), it searches
PATH for it. If there is a
/, then the first word of the command is taken to refer to a specific file by location.
./xx is different from
xx because of the
/ that it contains.
/xx would not work properly--it would try to run a file called
xx located in the root directory,
. represents the current directory,
ANSWERING IN SIMPLER WORDS:
In Shell prompt we can execute commands... The command are nothing but the name of executable file kept in particular directory such as like : bin, sbin... We can call executable files without specifying the extension name.
When we enter command the file is executed kept in such particular directory.
In this case of using
./command we are calling to executable file that is kept in the current prompt path (Present working Directory). You can get to know your current working directory of shell with command