Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Use source file or . file when the file must change the shell you are currently using. Use bash file or ./file when you want to run a command separately, without directly changing the calling shell’s variables, functions, options, or working directory. The key difference is execution context—not the file extension.
This comparison describes Bash. The two sourcing forms run commands in the current shell; bash file explicitly starts Bash to interpret a script; and ./file asks the system to execute a path, using the file’s declared interpreter when applicable.
How the four forms differ
| Form | What interprets the file | Where commands run | Practical effect |
|---|---|---|---|
source file |
The current Bash shell’s source builtin |
In the current shell context | Changes the file makes to shell state can persist after it returns. |
. file |
The current shell’s . builtin |
In the current shell context | Same basic use as source; this is the POSIX spelling. |
bash file |
A newly invoked Bash interpreter | In a non-interactive shell | Runs the file as a Bash script; its shell-state changes do not directly alter the caller. |
./file |
The system’s command-execution mechanism and, for a script, its declared interpreter when applicable | In a separate execution environment | Runs the named path as a command; executable permission and interpreter details matter. |
The Bash manual describes . as reading and executing commands in the current shell context. GNU Bash Reference Manual: Bourne Shell Builtins
What sourcing does to your current shell
source and . are builtins: the running shell reads the file and executes its commands as part of its own context. That is why a variable assignment, function definition, shell option change, or directory change made by a sourced file can remain in effect after the file finishes.
#1 Best Overall
- Used Book in Good Condition
For example, suppose settings.sh contains PROJECT_MODE=dev and cd "$HOME/project". Running . ./settings.sh makes those changes in the shell from which you issued the command. It does not start a new Bash interpreter to read the file.
Because the sourced commands run in the current shell, use this form only for files you trust. A command in the file has the authority of that shell; in particular, exit in a sourced file can end the shell session itself.
source and . are equivalent in Bash
In Bash, source file and . file serve the same purpose. The Bash manual classifies . as a POSIX-specified builtin and lists source as its alternative spelling. For shell code intended to work in POSIX shells generally, choose . rather than relying on every shell recognizing source.
What changes when you execute a file
bash file explicitly chooses Bash
When a filename is Bash’s first non-option argument, and you have not used -c or -s, Bash reads and executes that file in a non-interactive shell, then exits when the script finishes. This runs the file’s commands without directly changing the shell that launched it. The file need not be executable for this invocation, because you are asking Bash to read it.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsThis form explicitly selects Bash to interpret the file. The script’s shebang does not choose a different interpreter for bash file.
./file executes a path
The leading ./ means “the file named here in the current directory.” It is a path, not a synonym for sourcing, and it does not ask Bash to search PATH for a command named file. When Bash executes a command name containing a slash, it executes the named path in a separate execution environment. GNU Bash Reference Manual: Command Search and Execution
For a script invoked this way, the operating system uses its command-execution mechanism; on systems that support the convention, a first-line shebang such as #!/usr/bin/env bash identifies the interpreter. Direct execution generally requires the system to be able to execute the file, whereas bash file asks Bash to read it. GNU Bash Reference Manual: Shell Scripts
./file does not always mean “run this with Bash.” The file could be another kind of executable or a script that declares a different interpreter. Use bash file when Bash should interpret the commands regardless of the shebang.
Choose the form that matches your goal
- Load settings into the shell you are using: run
. ./settings.shor, in Bash,source ./settings.sh. - Run a Bash script without changing the caller’s shell state: use
bash script. - Run an executable at a path: use
./scriptwhen it is executable and its interpreter setup is appropriate. - Write a file for POSIX shells to load: use the
.spelling rather than assumingsourceis supported.
File lookup and common pitfalls
With source name or . name, the filename has no slash. Bash follows the builtin’s lookup rules: it searches PATH, with a current-directory fallback in some non-POSIX-mode cases; the sourcepath setting can affect PATH searching. To make the intended file unambiguous, write source ./name or . ./name. GNU Bash Reference Manual: Bourne Shell Builtins
Quick Recap
- Do not confuse a path with sourcing:
./scriptexecutes a path; it does not load changes into your current shell. - Do not assume the shebang applies when sourcing: sourcing reads commands in the current shell; it does not invoke the file’s shebang interpreter. A file written for another shell can therefore fail or behave unexpectedly when sourced in Bash.
- Use the right permission expectation: a sourced file does not need executable permission according to the Bash manual. Direct execution typically does.
- Keep the execution context in mind: separate execution does not directly change the caller’s shell state; sourcing does.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

