This question already has an answer here:

a question - in some case, I saw command line like this

. ./test.sh

I'm curious why use "." before "./test.sh" what condition we have to use "." before a command?

marked as duplicate by Michael Homer, Ulrich Schwarz, heemayl, cuonglm, Stephen Kitt Jan 11 '16 at 9:16

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.

  • I have read both threads above. @Micheal that one you mention as duplicate fails to explain adequately the consequences on the environment vars of sourcing a script. I agree more with Ulrich, but even then the mention of forking or not bash is buried in the 4th answer. – Rui F Ribeiro Jan 11 '16 at 8:22

Running . ./test.sh is similar to running source ./test.sh. It's not running the file test.sh as an executable. Instead it's running it's contents line by line into your current shell. So it could for example also modify your current environment.


Running . ./test.sh is the same as source ./test.sh. It runs the script in the current shell rather than a subshell (i.e. it does not fork). This may change variables of same name in the calling script, and it will leave variables and functions which were defined in ./test.sh also defined and visible after the call in the calling script.

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