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?

  • 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 08:22

2 Answers2

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.

Tarrasch
  • 216
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.

rexkogitans
  • 1,329