5

I've downloaded an installation package of weblogic server and in the README, there's this command to execute:

Linux/Mac
$ . ./configure.sh

It's not the first time I see this. Why is there an extra dot at the start of the command? When I do only ./configure.sh, the result is the same

  • Yes, it is indeed a duplicate. I apologize, but I didn't find the others because of the poor choice of words. – NeplatnyUdaj Nov 04 '13 at 09:58
  • No problem. Even knowing it, neither I found it directly, but following another question closed as its duplicate. – manatwork Nov 04 '13 at 10:08
  • I didn't see it either, but assumed it was here somewhere, given this is pretty basic functionality to the shells once you're aware of it's existence. – slm Nov 04 '13 at 10:52

1 Answers1

6

The dot (.) is a notation for executing commands from a file, that's been given as an argument to the dot. The contents of this file, say ./configure.sh, are executed in the current shell. The dot command originated with Bourne shell, and is available in others, for example, in Bash.

excerpt from Bash's 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
    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.

NOTE: Other shells such as csh have a similar command source, and many of the more modern varities support both the dot notation as well as the source command. Bash actually supports both.

Example

Here's an example where we'll set the variable $SOMEVAR in our current shell by sourcing a file with that variable defined.

Here's the sample file:

$ cat test.sh 
SOMEVAR="hi"

First we check to make sure that the variable, $SOMEVAR isn't already set in the current shell.

$ echo $SOMEVAR

$

Now we source it, and confirm that it's now set:

$ . ./test.sh 
$ echo $SOMEVAR
hi

Portability

Thanks to @ChrisDown for mentioning this. The dot (.) is specified as part of POSIX and so is portable, whereas the command source is not. See here in the The Open Group Base Specifications Issue 7 documentation, section: "2. Shell Command Language". Specifically this section.

excerpt

NAME

dot - execute commands in the current environment

SYNOPSIS

. file

DESCRIPTION

The shell shall execute commands from the file in the current environment.

If file does not contain a , the shell shall use the search path specified by PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the dot utility need not be executable. If no readable file is found, a non-interactive shell shall abort; an interactive shell shall write a diagnostic message to standard error, but this condition shall not be considered a syntax error.

slm
  • 369,824