Interpreter Selection
It tells the OS which program should execute the script.
Shell Script · Shebang
Shell Scripting · Lesson 3
Understand the role of shebang (#!) in shell scripts. Learn how interpreter path works in Linux. Difference between bash, sh and other interpreters. Best practices for portable scripts.
The shebang is the first line of a script that tells the operating system which interpreter should be used to execute the file.
It always starts with #! followed by the absolute path of the interpreter.
It tells the OS which program should execute the script.
Allows running scripts like normal commands using ./script.sh.
Helps scripts run consistently across different systems.
#!/bin/bash – Bash shell#!/usr/bin/env bash – Portable bash#!/bin/sh – POSIX shell#!/usr/bin/python3 – Python scriptA simple shell script using bash as the interpreter.
This makes the script portable across systems where bash path may differ.
Give execute permission and run the script directly.
If a script has no shebang, you must specify the interpreter manually.
#!/bin/bash../.Next lesson: Variables in Shell Scripting