I'm new to Linux. In the command below, why do I need to use a dot to execute the profile?
. ~/.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.
Pretty hard to tell without more context, but one usage is the Bash-specific file .bash_profile
to include the more generic (as far as Bourne shells go) file .profile
, since when Bash finds the first, it won't load the second one by itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With