The note is generated by “ChatGPT”.
đš source
- Executes a script in the current shell environment.
- Does not create a new shell process.
- All variable exports, alias definitions, and PATH modifications remain active after execution.
- Commonly used for reloading configuration files (e.g.,
source ~/.bashrc). - Bash and Zsh built-in command.
Example:
| |
â Reloads your Bash configuration immediately in the current session.
đš bash
- Starts a new Bash subshell to run the script.
- The parent shell does not inherit any environment changes.
- Safer for running scripts that should not affect your current session.
- Suitable for installation, automation, or isolated execution.
Example:
| |
â Runs the script, but changes (like export PATH=...) disappear when it exits.
đš .
- A POSIX-standard alias for
source. - Works in all POSIX-compliant shells (e.g.,
sh,dash,bash,zsh). - Functionally identical to
source.
Example:
| |
â Same as source ~/.bashrc, but more portable across shells.
âī¸ Comparison Table
| Command | Runs in Current Shell | Creates Subshell | Persists Env Changes | Portability |
|---|---|---|---|---|
source script.sh | â Yes | â No | â Yes | Bash/Zsh only |
. script.sh | â Yes | â No | â Yes | POSIX (universal) |
bash script.sh | â No | â Yes | â No | Bash only |
đ§ Quick Example
| |
Run it two ways:
| |
â Key Takeaway
- Use
bashwhen you want isolation. - Use
sourceor.when you want persistent changes in your shell session.