What are the differences between source scriptname.sh
, . scriptname.sh
and ./scriptname.sh
when executing scripts?
Running a program in Bash
Executing a script is simple in Bash and many other shells.
|
|
OR
|
|
The shell commands above will execute the scriptname.sh
script as a separate program from the command line. It may be any type of script.
Sourcing a script in Bash
When a file is sourced, it runs in the current user’s shell as if the commands were typed out.
|
|
OR
|
|
The most common use case is when scripts export environment variables.
|
|
|
|
Output:
|
|