Session and utilities

The source command

Runs a command file in your current shell, without opening a new process.

Syntax

source [-p ruta] archivo [argumentos]Try it in the terminal →

Most useful options

-p <ruta>Searches for the file in the folders of this colon-separated list instead of PATH. It exists only in recent versions of bash: bash 5.2 rejects it as an invalid option

Copy-ready examples

$ echo 'saludo=hola' > config.sh && source config.sh && echo $saludowrites a file with a variable, loads it into your shell and shows the variable.

Example output

hola
$ source ~/.bashrcreloads your settings without closing the terminal.
$ printf 'echo "entorno: $1"\n' > deploy.sh && source deploy.sh produccionpasses arguments: the file receives them as $1.

Example output

entorno: produccion
$ . ~/.bashrcthe same with the dot, which is another name for the same command.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
bash: falta.sh: No such file or directoryThe path does not point to any file, or the name without a slash is in neither PATH nor the current folder.Check the name with ls and pass the full path, for example source ./falta.sh.
bash: source: filename argument requiredYou called source without any file.Give the file: source ~/.bashrc.

Typical mistakes

  • Unlike running the script, source does not open a new process: the variables, functions and folder changes the file makes affect your session.
  • Without a slash in the name, source searches PATH first and then the current folder. With ./file.sh there is no search at all.
  • An exit command inside the file ends your current shell, because the file runs inside it.

Differences from similar commands

  • bash script.sh: runs the script in a new process: when it ends, its variables and functions vanish from your session.
  • exec: replaces the shell with the command and never returns to it. source runs the file and you stay in your shell.

Security

Source runs the whole file with your permissions and inside your session. Only load files you wrote or have reviewed.

Related commands

FAQ

What is the difference with the dot (.)?

None: in bash they are the same command with two names, and both forms take the same options.

Does the file have to be executable?

No. It only has to be readable: the manual says the file does not need execute permission.

How do I apply a change to ~/.bashrc without restarting the terminal?

Run source ~/.bashrc. The changes affect the current session; other open terminals will not see them until you reload them.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course