Usually, a ./file
is just a way to point to a file, which in this case, is equivalent to the PWD (present working directory) path followed by the file name used.
$ pwd
/home/isaac/me/bin/
$ realpath ./file
/home/isaac/me/bin/file
It also happens that a path at the start of a line (first argument or argument 0) signals the shell to try to execute that file. If it is a shell script, most probably, the shell will load it to execute it in a new execution environment. If it is some other form of valid executable, the shell will try to execute it via the kernel exec
command.
Adding an initial dot to a command line (only works if it is the whole argument zero) will allow a shell script (not an external executable) to be loaded with the same execution environment already present.
$ . ./file # that exact same file as above, now it is sourced
$ source ./file # an equivalent (but longer) command.
Of course, if the directory is not set in the path (not starting dot), some searching will be involved to find the specific file to be sourced.
In bash:
If filename does not contain a slash, filenames in PATH are used to find the directory containing filename.
And, if in POSIX mode, the PWD is also used to search for the filename
given.
test.sh
is not the same as./test.sh
(the first invokes aPATH
search), so are. test.sh
and. ./test.sh
different in the same way (the former invokes aPATH
search). Many shells seem to implicitly include.
at the end ofPATH
when doing a.
path search, but this behavior is not standard. Thus, it is more accurate to comparetest.sh
vs. test.sh
and./test.sh
vs. ./test.sh
.