Outside of a shell, such as running some other process, what does the term
current directory mean, and is it possible to execute a binary without specifying the full path or the preceding './', assuming that the
current directory contains the executable?
Yes, it is possible by setting up the search path appropriately (either containing your working directory explicitly or by containing "./"), but it is good practice to have the "./" in front of the program name. The reason is security: A malware could write an executable file with the name of a commonly used program (say,
ls) and the next call to
ls will execute the local copy instead of
/bin/ls. Therefore, standard PATH settings under UNIX do not contain "./".
You should better define what is the "other process" and what method it uses to launch a program.
In any case, the current working directory is a property of each and every process running so it might be used to locate a program to run. Whether it is safe to implement it that way is questionable.
Well a quick workaround would be creating an alias. This creation can be added to the .bashrc to have it added during startup.
The Unix/Linux/*BSD kernel has always kept track of working directory. The
fchdir() system calls have been around for as long as the C language has been around.
If you write a C language program and use
execve(), it's up to your program to specify the
filename argument of
execve(). The kernel will find executables in the current working directory, or relative to it, if you give a filename argument like "some_executable" or "subdir/some_executable", the kernel will find the executable (if it exists and is executable).
I realizes the modern shells (zsh at least) blur the current working directory a bit so as to be able to
cd into a symbolic link, and
cd .. back up to the directory containing the symbolic link, but the kernel-based tracking of current working directory is still present. On linux machines you can
ls -l /proc/$$/cwd to see exactly what the kernel thinks that directory is named.