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

Shebang Line का परिचय

Shebang एक lunchbox पर नाम के label जैसा है जो बताता है कि इसे कौन खोलेगा। यह computer को बताता है कि file को कौन सा helper program पढ़े और run करे।

In this page:

  1. The Shebang Line
Syntax
bash
#!/path/to/interpreter
# script commands follow

The Shebang Line

एक script की पहली line, #!/bin/bash, shebang है — यह operating system को बताती है कि सीधे execute होने पर file को कौन सा interpreter run करे।

इसके बिना, ./script.sh गलत shell उपयोग कर सकता है और unexpectedly behave कर सकता है। Shebang बिल्कुल पहली line होनी चाहिए, इसके ऊपर कोई blank line नहीं।

Note: #!/usr/bin/env bash एक ज़्यादा portable shebang है जो bash को PATH पर जहां भी हो ढूंढ लेता है।

उदाहरण: The Shebang Line

bash
#!/bin/bash
# This shebang tells the OS to run this file with bash
echo "Running under: $0"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. #! से पहले एक space या blank line लगाना, इसलिए यह shebang के रूप में नहीं पढ़ा जाता और system एक default shell उपयोग करता है।
  2. #!/bin/bsh जैसा गलत interpreter path लिखना, जो bad interpreter: No such file or directory देता है।
  3. Script को Windows line endings (CRLF) के साथ save करना, इसलिए interpreter bash\r के रूप में पढ़ा जाता है और fail हो जाता है।

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.