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

This question already has an answer here:

I saw the command like "." in some shell source code, but I don't know what it does. So, I have tried this. And, that .sh file is executed.

However, I don't understand how "." works. Can you explain?

share|improve this question

migrated from Mar 23 '13 at 18:03

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Daniel Beck Mar 23 '13 at 18:43

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.

The . command (which has a synonym, source, in bash, but not in most other Bourne shell derivatives) reads the named file as part of the current shell.


$ cat
export ENVVAR="Welcome"
echo $ENVVAR
$ echo $ENVVAR

$ echo $ENVVAR

$ .
$ echo $ENVVAR

NB: Cheat 1: I assume is executable. Cheat 2: I assume is in a directory on $PATH.

It means that environment variables set in affect the current shell. By contrast, executing a command without the . does not affect the environment of the current shell. The . mechanism is used when .profile and related files are read, for example.

Note that . looks for simple names (like with no slash in it) on PATH, but the file only has to be readable; it does not have to be executable.

share|improve this answer
Note that when bash is not in POSIX mode, ./source also checks the current directory if no file is found using PATH. – chepner Mar 23 '13 at 15:31
@chepner: That's entirely plausible. I haven't bothered to experiment with whether the current directory is searched first or last. For the most part, it is not important to this question, which is about the high-level difference between sourcing and executing a script. I agree, though, that it does matter if you're going to make a bullet-proof system depending on such a script. – Jonathan Leffler Mar 23 '13 at 18:30
Thank you guys. I understand. – sinapps Mar 24 '13 at 18:03

It's a shorthand for this, nothing more:


share|improve this answer
The dot command pre-dates the source command by years. It was in the original Bourne shell. The C shell had the source command for the same job; bash imported that as a synonym for . some time later. – Jonathan Leffler Mar 23 '13 at 15:16

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