1

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?

1
  • 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. Jan 11, 2016 at 8:22

2 Answers 2

3

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.

1

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.