When you enter a command name ( a.out is no different from any other command name in this regard), the shell looks for an executable file with that name. It performs this search using a list of directory names stored in the $PATH environment variable.
You can see your current $PATH by typing
echo $PATH
on the command line. A typical value might be something like
/usr/bin:/bin
although you will probably have additional directories.
Since a.out is in your current working directory (type pwd to see what that directory is), and your current working directory is probably not in your $PATH , you cannot execute it just by typing a.out .
Because you can link to your current directory as . , you can (and should) execute the command by typing
./a.out
NOTE: you may have one . in your $PATH , but this is considered a bad idea, as it makes random commands too random. If . located in front of your $PATH , imagine I ask you to cd into my directory and type ls - but I installed a file called ls that does something unpleasant. The room . at the end of your $PATH reduces this risk, but does not completely eliminate it. It is best to develop the habit of adding a file name to ./ if you want to execute it from the current directory.
(I ignored the fact that aliases, functions, and shell built-in commands can also be executed this way.)
Keith thompson
source share