Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ whatis source
source: nothing appropriate.
$ man source
No manual entry for source
$ source
bash: source: filename argument required
source: usage: source filename [arguments]

It exists, and it is runnable. Why isn't there any documentation about it in Ubuntu? What does it do? How can I install documentation about it?

share|improve this question
1  
related: superuser.com/questions/176783/… – lesmana Jan 17 '11 at 21:59
19  
you forgot $ type source source is a shell built-in – bnjmn Oct 9 '13 at 6:00
    
My shell returned this $ whatis source source (1) - bash built-in commands, see bash(1). Also, man source takes me to the BASH_BUILTINS(1) man pages. This is on Fedora btw, no idea why those debian packages are un-(or badly)-documented. – arielnmz Aug 20 '14 at 12:29
    
@lesmana, great link. That linked answer is the more thorough answer to this question. – Scott Sep 5 '14 at 15:02
    
Try "help source" – Jasser Sep 19 '15 at 14:12
up vote 191 down vote accepted

source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in '.' (period).

Syntax
      . filename [arguments]

      source filename [arguments]
share|improve this answer
2  
Is source a bash specific command or do other shells have it too? (I'm asking to get tags right on the question...) – Jonik Sep 24 '09 at 11:17
2  
Afaik, source was present in the Bourne shell and hence probably present in all its descendants. en.wikipedia.org/wiki/Bourne_shell. I know that not all shells have the source command, less certain about which shells do contain it. – nagul Sep 24 '09 at 11:47
7  
@nagul, source was not present in the Bourne shell, it is a GNU extension that came much later. The original and still portable syntax (POSIX) is to use the "dot" command, i.e. . instead. I personnaly never use source given the fact it is longer to type and has no added value. I guess its main purpose is to make scripts more readable for newbies. – jlliagre Aug 2 '13 at 14:02
6  
@jlliagre my personal "explain why have source" is that source is not only more descriptive, but it looks like something other than a typo. I've had people skip the period/dot when I send tech commands in email. – Rich Homolka Mar 10 '14 at 18:31
2  
One common use for this command is for a shell script to source in a "configuration file" that contains mostly variable assignments. The variable assignments then control things the rest of the script does. Of course, a good script will set variables to sensible defaults before the source, or at least check for valid values. – LawrenceC Mar 10 '14 at 18:41

Be careful! ./ and source are not quite the same.

  • ./script runs the script as an executable file, launching a new shell to run it
  • source script reads and executes commands from filename in the current shell environment

Note: ./script is not . script, but . script == source script

http://askubuntu.com/questions/182012/is-there-a-difference-between-and-source-in-bash-after-all?lq=1

share|improve this answer
14  
You are mixing up ./command and . script. source-command is same as .-command. Using ./meh says run script/binary named meh in the current directory, and got nothing to do with source/. -command. As explained in answer in your link. – Joakim Elofsson Aug 1 '13 at 13:14
2  
@JoakimElofsson It is mentioned in the link, but I will modify the answer to avoid missunderstand. Please correct it. – damphat Aug 2 '13 at 11:45

It is useful to know the 'type' command:

> type source
source is a shell builtin

whenever something is a shell builtin it is time to do man bash.

share|improve this answer
1  
Always know something new when reading man ) – user83293 Aug 15 '13 at 8:41
7  
You can also use help {builtin-name}, i.e. help source. – LawrenceC Mar 10 '14 at 18:39
1  
help doesn't work everywhere (atleast in zsh). type does. – kumar_harsh Mar 28 '14 at 8:35
    
To amplify: if you are using bash, and if you know (perhaps via 'type') it is a built-in command, then 'help' will get you directly to the paragraph of documentation you want without wading through 4,184 lines of 'man bash' text. – Ron Burk Apr 29 '15 at 19:43

. (a period) is a bash shell built-in command that executes the commands from a file passed as argument, in the current shell. 'source' is a synonym for '.'.

From Bash man page:

. 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, file
       names in PATH are used to find the  directory  containing  file‐
       name.   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

'source' is the long version of '.' command. On the bash prompt one can do:

source ~/.bashrc

to reload your (changed?) bash setting for current running bash.

Short version would be:

. ~/.bashrc

The man page:

. 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 executed from filename. If 
    filename does not contain a slash, file names 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 short
    builtin command is turned off, the PATH is not searched. If any arguments
    are supplied, they become the positional 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

source command executes the provided script (executable permission is not mandatory) in the current shell environment, while ./ executes the provided executable script in a new shell.

source command do have a synonym . filename.

To make it more clear, have a look at the following script, which sets the alias.

make_alias

#! /bin/bash

alias myproject='cd ~/Documents/Projects/2015/NewProject'

Now we have two choices to execute this script. But with only one option, the desired alias for current shell can be created among these two options.

Option 1: ./make_alias

Make script executable first.

chmod +x make_alias

Execute

./make_alias

Verify

alias

Output

**nothing**

Whoops! Alias is gone with the new shell.

Let's go with the second option.

Option 2: source make_alias

Execute

source make_alias

or

. make_alias

Verify

alias

Output

alias myproject='cd ~/Documents/Projects/2015/NewProject'

Yeah Alias is set.

share|improve this answer

This is a shell built-in command, read the manual for your shell.

which source

man bash
share|improve this answer
2  
Mentioning "shell built-in command" is good, but this answer would be better if combined with that of Jawa. :) – Jonik Sep 24 '09 at 11:19

When in doubt, best thing to do is use the info command.

[root@abc ~]# info source

BASH 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, file
              names  in  PATH  are used to find the directory containing file-
              name.  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

Type this command : "help source" in your shell

you will get output like this :

source: source 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.
share|improve this answer

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.