← Back to Bash Course | Chapter 1: Setup & Basics | Lesson 4 of 12

The Shebang Line

In this page:

  1. The Shebang Line

The Shebang Line

The first line of a script, #!/bin/bash, is the shebang — it tells the operating system which interpreter should run the file when executed directly. Without it, ./script.sh might use the wrong shell and behave unexpectedly. The shebang must be the very first line, with no blank line above it.

Note: #!/usr/bin/env bash is a more portable shebang that finds bash wherever it is on the PATH.

Example: The Shebang Line

bash
#!/bin/bash
# This shebang tells the OS to run this file with bash
echo "Running under: $0"

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.