. (dot) - Run a shell file in the current environment

Format

. file [argument ...]

Description

. (dot) runs a shell script in the current environment and then returns. Normally, the shell runs a command file in a child shell so that changes to the environment by such commands as cd, set, and trap are local to the command file. The . (dot) command circumvents this feature.

If there are slashes in the file name, . (dot) looks for the named file. If there are no slashes . (dot) searches for file in the directories specified in the PATH variable. This may surprise some people when they use dot to run a file in the working directory, but their search rules are not set up to look at the working directory. As a result, the shell does not find the shell file. If you have this problem, you can use:
 . ./file
This indicates that the shell file you want to run is in the working directory. Also, the file need not be executable, even if it is looked for on the PATH. If you specify an argument list argument ..., . (dot) sets the positional parameters to the arguments while running the shell script, then restores the positional parameters of the invokers. If no argument list is specified, the shell script has the same positional parameters as the invoker. Any changes made to the positional parameters (for example, by the set command) in the shell script remain in effect when the . (dot) command ends.

Usage notes

  1. . (dot) is a special built-in shell command.
  2. The file specified is treated as a shell script containing shell commands. Files that are not shell scripts (such as REXX execs, executable programs) should not be specified as file.

Localization

. (dot) uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_MESSAGES
  • NLSPATH

Exit values

1
The path search failed.
2
Failure because of an incorrect command-line option.

Otherwise, the exit status is the exit status of the last command run from the script.

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

Related information

cd, set, sh, trap