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.

  • 8
    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) Mar 19, 2014 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?
    – Panther
    Mar 19, 2014 at 17:57
  • 2
    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, 2014 at 17:57
  • @JasonConti darn, sorry, just saw your comment, happy to delete if you want to post an answer.
    – terdon
    Mar 19, 2014 at 18:10
  • 1
    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, 2014 at 1:59

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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