4

What is the difference between "." "./" and "source" ?

marked as duplicate by mdpc, John1024, Jeff Schaller, jasonwryan, Scott Sep 27 '16 at 3:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5
./script

The above executes the script. When the script is done, any changes that it made to the environment are discarded.

. script

The above sources the script. It is as if the commands had been typed in directly. Any environment changes are kept.

source script

This also sources the script. The source command is not required by POSIX and therefore is less portable than the shorter ..

0

The dot is an useful idea to quickly type several things.

In the web, a dot is the last value a web address have:

unix.stackexchange.com.

In the directory tree, a dot is "this directory", whichever is the pwd (present working directory). And is usually used with an slash after it:

ls -d ./

Will print this directory (the -d option), which is simply ./ again.
But:

ls ./

Will list all files and directories in the pwd.

In the shell, a dot also means: "source a file".
Thus, this are equivalent:

. ./a_file
source ./a_file

And you can excute the a_file in the pwd (here) if it has the execute bit on.

$ ls -l ./a_file
-rwxr--r-- 1 user user 8370 sep 26 19:32 ./a_file

Has the x (execute bit) on, and thus:

$ ./a_file

Will (try to) execute it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.