Why use a dot to execute the profile?

As Noufal mentioned, . is an alias for source.

By sourcing the file, all commands are executed within the context of your current bash session, which means that all environment variables which it exports will now be available to you.

If you run the script instead of source it, it is executed in a subshell and exported variables are not passed on to your session. In effect, that pretty much defeats the purpose of .profile.

As a demonstration, say you have the file test.sh:

#!/bin/bash
# in test.sh
print "exporting HELLO"
export HELLO="my name is Paul"

If you execute it:

[me@home]$ bash test.sh
exporting HELLO
[me@home]$ echo $HELLO

Nothing gets printed out since $HELLO is not defined in your current session. However, if you source it:

[me@home]$ . test.sh
exporting HELLO
[me@home]$ echo $HELLO
my name is Paul

Then $HELLO will be available in your current session.


The period operator is an alias for the source command. Details here.

Tags:

Unix