When I insert, for example, unix.stackexchange.com followed by Enter in terminal, I get the following error:unix.stackexchange.com: command not foundThis is ok and as I expected. But when I insert http://unix.stackexchange.com, I get another error message:bash: http://unix.stackexchange.com: No such file or directoryI do not ask about why I get errors. I want to know why these are different and, eventually, which process/function handles them?
Different error messages when using different strings in terminal
bash;gnome terminal;error handling;stderr
As also ewhac pointed out, the error messages differ because the latter command line contains forward slashes (/), which causes your shell to interpret it as a file path.Both errors originate from your shell, which in this case is bash (which is evident from the second error message).More specifically, the first error originates from the execute_disk_command() function defined in execute_command.c in the bash-4.2 source code. The execute_disk_command() function calls search_for_command() defined in findcmd.c, which, in case the specified pathname does not contain forward slashes, searches $PATH for the pathname. In case pathname contains forward slashes, search_for_command() does not perform this lookup. In case search_for_command() does not return a command, execute_disk_command() will fail with the command not found internal error.The second error originates from the shell_execve() function, also defined in execute_command.c. At this point in your scenario,search_for_command() would have returned successfully because there would not have been any lookup needed, and execute_disk_command() has called shell_execve(), which in turn performs the execve() system call. This fails, because the file execve() attempts to execute does not exist, and execve() indicates this by setting errno appropriately. When execve() fails, shell_execve() uses strerror() to report the corresponding file error message (No such file or directory) and exits the shell immediately on the error.