5

This question already has an answer here:

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?

marked as duplicate by G-Man, Anthon, garethTheRed, X Tian, Bananguin Oct 12 '15 at 8:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.