5

What does dot mean in line 8 of the following code snippet, from the source of /etc/profile in Mac OS X Mavericks terminal.

  1 # System-wide .profile for sh(1)
  2 
  3 if [ -x /usr/libexec/path_helper ]; then
  4         eval `/usr/libexec/path_helper -s`
  5 fi
  6 
  7 if [ "${BASH-no}" != "no" ]; then
  8         [ -r /etc/bashrc ] && . /etc/bashrc
  9 fi
George
  • 3,384
  • 5
  • 40
  • 64

2 Answers2

5

In bash, . is another way to spell source. So this line is the same as this:

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && source /etc/bashrc
fi

source interprets the file as if the content was included at the location of the source command. The difference with executing it is that it can set alias or define function or variables.

Sylvain Defresne
  • 42,429
  • 12
  • 75
  • 85
  • 1
    Technically, `source` is another way to spell `.`. `.` is a standard POSIX command; `source` is a more readable synonym provided by some shells. – chepner Apr 15 '14 at 14:38
  • 1
    However, note that `source` should not be used in `.profile`, which may be read by other POSIX-compatible shells which don't understand the `source` command. – chepner Apr 15 '14 at 14:46
2

According to Bash Prompt HOWTO:

When a file is sourced (by typing either source filename or . filename at the command line), the lines of code in the file are executed as if they were printed at the command line. This is particularly useful with complex prompts, to allow them to be stored in files and called up by sourcing the file they are in.

Felix Yan
  • 14,841
  • 7
  • 48
  • 61
  • Thank you for this good explanation on the verb "sourced", as seen also in this [doc](https://help.ubuntu.com/community/EnvironmentVariables). – George Apr 15 '14 at 13:35