Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

I saw a post about fix your alias in .bashrc.

And he says after you put your alias in .bashrc , you need to use:

. ~/.bashrc

I do not quite understand what the first dot(' . ') does here. What's its function and what is it called?

share|improve this question

marked as duplicate by Radu Rădeanu Jul 16 at 18:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 4 down vote accepted

Interesting... the name seems to be dot-command, in your case it includes the .bashrc into the calling shell program (in your case, your bash environment). As you are calling it from the command line, it updates your environmental variables, as variables are set in .bashrc.

echo "FOO=bar" > test
echo $FOO

no result, env variable not set. But after you source the "test" file:

. test

the env variable FOO is set and

echo $FOO

result in the output of

bar

I found the following info here:

Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.

Also, see this question. In bash, . is the same as source.

share|improve this answer
    
Awesome, but I find I can't excute ". test", I need to add a dot before test, and ". .test" is successful –  Zen Jul 16 at 4:57
    
By the way, what do you mean by "script"? which script? –  Zen Jul 16 at 4:59
    
"script" was referring to a script that is calling "." I will improve my phrasing in the reply. Regarding execution of test: test should not be executed, it is just a one-line file. –  noleti Jul 16 at 5:37
    
Regarding . test, you have to do chmod +x test first to make it executable. –  saiarcot895 Jul 16 at 12:23
2  
Here . means sourcing. –  Avinash Raj Jul 16 at 14:20

If you want to check something in bash, use type and man.

In your case you want to know what is .

$ type .
. is a shell builtin

shell builtin means that . is inside bash shell. You can find information about shell builtins in bash manual page. There is a big section SHELL BUILTIN COMMANDS

$ man bash

SHELL BUILTIN COMMANDS
       Unless otherwise noted, each builtin command documented in this section
       as accepting options preceded by - accepts -- to signify the end of the
       options.   The  :, true, false, and test builtins do not accept options
       and do not treat -- specially.  The exit, logout, break, continue, let,
       and  shift builtins accept and process arguments beginning with - with‐
       out requiring --.  Other builtins that accept  arguments  but  are  not
       specified  as accepting options interpret arguments beginning with - as
       invalid options and require -- to prevent this interpretation.
       : [arguments]
              No effect; the command does nothing beyond  expanding  arguments
              and  performing any specified redirections.  A zero exit code is
              returned.

        .  filename [arguments]
       source filename [arguments]
              Read and execute commands from filename  in  the  current  shell
              environment  and return the exit status of the last command exe‐
              cuted from filename.  If filename  does  not  contain  a  slash,
              filenames  in  PATH  are  used  to find the directory containing
              filename.  The file searched for in PATH need not be executable.
              When  bash  is  not  in  posix  mode,  the  current directory is
              searched if no file is found in PATH.  If the sourcepath  option
              to  the  shopt  builtin  command  is turned off, the PATH is not
              searched.  If any arguments are supplied, they become the  posi‐
              tional  parameters  when  filename  is  executed.  Otherwise the
              positional parameters are unchanged.  The return status  is  the
              status  of  the  last  command exited within the script (0 if no
              commands are executed), and false if filename is  not  found  or
              cannot be read.
share|improve this answer

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