8

What is the difference between

. script.sh
./script.sh

and

source script.sh

?

AdminBee
  • 22,803
ankagarwal
  • 91
  • 1
  • 1
  • 2

1 Answers1

15
./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 ..

John1024
  • 74,655