🐧 Linux / Shell Scripting
Beginner
How do you run a shell script?
Answer
Three main ways: (1) Make it executable and run directly: chmod +x script.sh then ./script.sh. (2) Pass it as an argument to the interpreter: bash script.sh or sh script.sh — this works even without the executable bit or shebang. (3) Source it (run in the current shell): source script.sh or . script.sh — this shares the script's environment (variables) with the calling shell, unlike methods 1 and 2 which run in a subprocess. Use sourcing for scripts that set environment variables (like activating a virtualenv or loading secrets).