When using bash shell, I sometimes keep environment variables in a text file which I copy/paste the content of, eg exports.txt:
export FOO=bar
export FIZZ=buzz
Someone showed me instead of copy/paste, I could type in the terminal
. exports.txt
which would have the same effect as copy/paste.
What is the mechanism by which this 'dot space filename' command works? It's hard to think of search terms for it.
I want to understand what is happening and the more general details of what this one-liner is doing.
Best Answer
The
.
("dot") command is a synonym/shortcut for the shell's built-insource
command.It causes the named shell script to be read in and executed within the current shell context (rather than a subshell). This allows the sourced script to modify the environment of the calling shell, such as setting variables and defining shell functions and aliases.