Quote:
Originally Posted by
sudon't
I was only wondering why, when you are in the same directory as a file, (not only executables), to access it, you only need its name.
The open() system call, which is used to open a file for reading/writing, supports relative paths. When the path to the file does not contain any slashes, it is designed to look in the current working directory.
The exec*() family of system calls/library functions used to execute a file do not behave in this way. Some require an absolute path. Others (the ones with a p in their name), when the path provided does not contain a slash, will search only the directories in the $PATH environment variable.
Security aside, the PATH lookup mechanism is a convenience which saves a lot of typing. Further, since all unix-like systems do not agree on exactly where every executable should be placed, $PATH lookup insulates scripts from these differences, improving portability.
If you really wanted command invocation to work the way that file opening works, simply set PATH to
.. Absolute paths to commands never use PATH. Relative paths will only look in the current working directory. Such a configuration, however, if enforced from the kernel onwards, would severely break any extant unix. Boot scripts, shell profiles, software installation scripts, cronjobs, and more would all have to be rewritten.
Regards,
Alister