Bash & Shell Scripting (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is the Shebang (`#!/usr/bin/env bash`) line and why is it used?
junior Levelbash-shellBasic
In Simple Words:
The shebang (#!) is the very first line of an executable script:
- Tells the Linux kernel which interpreter binary to launch to execute the script:
#!/bin/bash: Hardcodes the binary path (may fail on systems where Bash lives in/usr/local/bin).#!/usr/bin/env bash(Best Practice): Uses theenvutility to dynamically resolve the location of thebashexecutable from the user's$PATH.
- Must have executable permissions set:
chmod +x script.sh.