bash man page:
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environment...
"Sourcing" is the quite generic term here. It means executing the commands from the script file as if you type them one line after the other. You stay in your same bash, and also have all the variables and settings.
"Running" a script includes defining how exactly. Often you call a interpreter. bash script.sh
is just like perl script.pl
. The suffixes don't matter. What matters is that first "binfmt" line: #!...
: ./script
or script
(if it is in $PATH) is all that is needed.
. script
(sourcing)
./script
("running", needs +x)
is not the same, technically.
A shell is your "entire" session, in a way. Ctrl-D has a similar effect. It can be controlled, but since a interactive shell is just like a script, it is logical.
Try
]# ps
PID TTY TIME CMD
18768 pts/1 00:00:00 ps
18994 pts/1 00:00:00 bash
]# bash
]# bash
]# ps
PID TTY TIME CMD
18780 pts/1 00:00:00 bash
18781 pts/1 00:00:00 bash
18782 pts/1 00:00:00 ps
18994 pts/1 00:00:00 bash
]# exit
exit
]# exit
exit
]# ps
PID TTY TIME CMD
18784 pts/1 00:00:00 ps
18994 pts/1 00:00:00 bash
]#
...to see how you can pile a shell upon another, and also exit.
This all has to do with processes and jobs.