What does . /path/to/a/shell-script-file
do exactly? I mean obviously it executes that shell script but why put that .
followed by a space before the path/name of the script file?
Asked
Active
Viewed 182 times
5
-
I missed the space after the period, so my answer was totally inaccurate and I deleted it. – Wildcard Oct 12 '15 at 02:13
-
Possible duplicate of Different ways to execute a shell script Related: running a script with “.” and with “source”. – G-Man Says 'Reinstate Monica' Oct 12 '15 at 03:20
2 Answers
10
.
or source
tells the shell to execute the script itself, instead of forking a sub-shell to run it in.
This allows the script to modify the environment of the shell.
For example, if you have a script that sets certain environment variables or defines aliases then running it without .
will define those things in a sub-shell, and they will disappear when the sub-shell terminates. Running it with .
will define them in the current shell.

cas
- 78,579
1
Say you have a file of custom environment settings (aliases, additions to $PATH, etc). Call the file custom_env
.
Usually this stuff will go in your .profile
or .bashrc
. But sometimes you might want it in separate file, then you can apply it to your session as needed, e.g.
. ./custom_env

roblogic
- 227