Why use a point to execute a profile

Hey guys I'm new to Linux.

In the command below, why does she use a dot to execute a profile?

. ~/.profile 
+6
unix
source share
3 answers

As Nufal noted,. is an alias for source .

When searching for a file, all commands are executed in the context of the current bash session, which means that all environment variables exported by it will now be available to you.

If you run the script instead of the source, it is executed in a subshell, and the exported variables are not passed to your session. Essentially, this pretty much hits the .profile target.

As a demonstration, let's say you have a test.sh file:

 #!/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 prints because $HELLO not defined in your current session. However, if you use it:

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

Then $HELLO will be available in your current session.

+11
source share

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

+4
source share

It’s quite difficult to tell without context, but one use is the Bash -special .bash_profile file to include the more general (as far as the Bourne shell is concerned) .profile file, because when Bash finds it in the first place, it will not load the second one by itself to myself.

+1
source share

All Articles