While I was executing a C program in terminal I wrote:
gcc -o demo demo.c
./demo
Actually my doubt is why we write ./
before demo
and what does it mean?
While I was executing a C program in terminal I wrote:
gcc -o demo demo.c
./demo
Actually my doubt is why we write ./
before demo
and what does it mean?
When we execute any command in the terminal it is going to look for it in the PATH environment variable. By using ./ (relative path) we are telling the shell to look for that command in our current directory.
Check echo $PATH
There are two way to execute any commands
When bash interprets the command line, it looks for commands in locations described in the variable $PATH. To see it type:
echo $PATH
Normally, he current directory is not in that list. The reason for not having the current directory on that list is security.
The
./
says: look in the current directory for my command rather than looking at all the directories specified in $PATH.
More about:
The "./" before a file name stand for "execute this file in th current directory" if the file that you want to execute is not in the same directory you are in you will need to specify the path o the file like this:
Xxxxx@xxxx /Documents/filetoexecute