Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I was under the impression that source was a synonym for . in bash. However, it seems that in the .profile file, source doesn't work. This youtube video demonstrates that when source is used in ~/.profile to source a file foo, the variable defined in that file is not exported to subsequent shells. However, if instead the file is sourced using ., the variable is exported as expected.

Note that when I use source, the environment variable does NOT get exported, but when I use . it does.

share|improve this question
Lightdm sources .profile in /bin/sh which is dash by default, and dash doesn't have a source command, it is a bash extension (see /usr/sbin/lightdm-session) – Jason Conti Mar 19 '14 at 17:57
They are the same. Post (pastebin) the contents of all your files, including the one you are sourcing. And what shell are you using ? bash or zsh? – bodhi.zazen Mar 19 '14 at 17:57
Please include the explanation in your question so we don't need to go and watch some random youtube video to understand the issue. – terdon Mar 19 '14 at 17:57
That's it Jason! Please answer so I can accept. – dmd Mar 19 '14 at 18:02
This is not a duplicate, please don't close. The OP knows they're supposed to be identical and has found a particular case where they appear not to be. – terdon Mar 20 '14 at 1:59
up vote 8 down vote accepted

They are exactly the same, as explained in man bash:

.  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 shopt builtin command is turned
    off, the PATH is not searched.  If any argu‐ ments 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.

The issue here is that source is a bash thing, the standard is actually .. Your .profile is only read by login shells and by some (not all) login managers. However, login managers (such as lightdm) will attempt to read (source) the file using the system's default shell, normally /bin/sh. On Debian-derived systems, /bin/sh is a symlink to /bin/dash and dash is a very simple, POSIX-compliant shell that is not bash and has no knowledge of the source keyword.

Therefore, the command is ignored, the file is not sourced and the variable is not defined. To illustrate:

$ cat foo
$ source foo
$ echo $myvar

The same thing in dash:

$ echo $0
$ source foo
dash: 11: source: not found
$ . ~/foo  ## dash needs the full path
$ echo $myvar
share|improve this answer

Your Answer


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.