Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I enter a eg. a new alias into my .bashrc file I can't use it in that terminal window immediately and until recently I thought I had to restart the terminal to reload the .bashrc file. Then I found out somewhere that if I write

. .bashrc

this will reload the .bashrc file in the current window and I don't have to restart. This works fins but what is actually happening? Why does this reload the .bashrc file?

share|improve this question
1  
With ., you "source" the file. Meaning it is being executed basically –  Oliver Salzburg Mar 14 at 9:22
    
possible duplicate of What does source do? –  Dan D. Mar 14 at 11:39
1  
@DanD. while the answer is the same, the question sounds quite distinct to me. –  Calimo Mar 14 at 12:41
1  
@Dan D. this question is more about the mening of . . Up until now I always thought about . as a shorthand for the current directory and .. as a shorthand for the parent directory. I never realised . was an alias for source (which in turn was a completely new concept for me). If someone comes here and wants to know the difference I found What is the difference between executing a bash script and sourcing a bash script? to be very helpfull. –  Spade Mar 14 at 13:36
add comment

3 Answers 3

up vote 16 down vote accepted

Because . is a command.

It's a shell built-in command, that reads the named file and executes the commands therein in the current shell process.

The Bourne Again shell also has source as a synonym for this command. But this is a Bashism (that the Bourne Again shell took from the C Shell). Albeit it is a Bashism that the Bourne Again shell shares with the TENEX C Shell, the Z Shell, and others (but not the Korn shell, note). The Single UNIX Specification only standardizes ..

Also note that the behaviour of ./source subtly changes dependent from whether the Bourne Again shell is being run in its POSIX-compatible mode or not. (Again this is like other shells, although their non-standard behaviours are not the same as one another's. With the Z Shell, for example, there is a precompiled shell script mechanism, and source subtly differs from . in its search path handling. The Korn shell's . will run shell functions, for another example.)

~/.bashrc is merely one of several files whose contents are (dependent from how the shell process is invoked) automatically sourced at shell startup. There's nothing prohibiting it from being manually sourced. Although if its actions aren't idempotent, you might have some fixup work to do afterwards.

Further reading

share|improve this answer
add comment

help . would tell you:

.: . filename [arguments]

Execute commands from a file in the current shell.

Read and execute commands from FILENAME in the current shell.  The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.

Saying . .bashrc executes (sources) the file .bashrc which makes the changes made to the file available in the current session.

By default, ~/.bashrc would be read at login.

. is a synonym for source.

share|improve this answer
add comment

The . command is the same thing as the source command, which executes your .bashrc file. This adds all the aliases you have defined and any other shell settings/variables into the current environment. From source's help page:

source: source filename [arguments]
    Execute commands from a file in the current shell.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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