1. What is the purpose of the shebang (#!) line at the beginning of a shell script?
The shebang (#!) on the first line tells the system which interpreter to use for executing the script. Common shebangs: #!/bin/bash for Bash scripts, #!/bin/sh for POSIX shell scripts, #!/usr/bin/env python3 for Python (uses env to find Python in PATH). The kernel reads this line when you execute the script directly (./script.sh), passing the script to the specified interpreter. Without shebang, the script runs with the current shell (often bash), which might not be what you want. Use #!/bin/bash when using bash-specific features like arrays, [[ ]], and extended syntax. Use #!/bin/sh for portable scripts that should run with any POSIX-compliant shell. The env approach (#!/usr/bin/env bash) is more portable across systems with different installation paths. Note: shebang must be the very first line with no preceding whitespace or blank lines. Make script executable with chmod +x script.sh. Then run with ./script.sh. Understanding shebang is fundamental for writing scripts that execute correctly and portably across different environments.