Sobes.tech
Junior

What is a shebang?

sobes.tech AI

Answer from AI

The shebang (#!) is a sequence of characters at the beginning of an executable script that indicates to the operating system or program loader which interpreter should be used to run the rest of the file.

The system reads the line starting with #! and uses the path specified after it to invoke the interpreter, passing the script's path as an argument.

Examples:

#!/bin/bash
# This script will be executed with bash

echo "Hello from bash!"
#!/usr/bin/env python3
# This script will be executed with the first found python3 in PATH

print("Hello from Python!")

Using #!/usr/bin/env is recommended because it allows finding the interpreter in the $PATH environment variable, making the script more portable across systems with different file locations.