Interview Prep/Linux/Packages, Shell & Text Tools

What is the difference between `source script.sh` and `./script.sh`?

BeginnerConceptPackages, Shell & Text Tools
Answer

./script.sh runs in a new child process (using the shebang interpreter), so variables and cd do not affect your shell; it needs execute permission. source script.sh (or . script.sh) runs the commands in the current shell, so exported variables and directory changes persist. That is how you load venv/bin/activate or a .env file.

All Linux questions Roadmap: Linux

More on Packages, Shell & Text Tools