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

Scripts चलाना

एक script run करना एक cook को एक recipe हाथ में देने जैसा है: आप हर बार 'यह recipe follow कीजिए' कह सकते हैं, या इस पर एक note चिपका सकते हैं जो कहता है कि cook इसे अपने आप उपयोग कर सकता है।

In this page:

  1. Scripts Run करना
Syntax
bash
bash script_name.sh

chmod +x script_name.sh
./script_name.sh

Scripts Run करना

एक Bash script दो तरीकों से run होता है: इसे सीधे bash interpreter को pass करके, या इसे executable बनाकर अपने खुद के program की तरह run करके।

bash script.sh permissions को देखे बिना हमेशा काम करता है। इसे सीधे ./script.sh के रूप में run करने के लिए पहले file पर execute permission चाहिए।

Note: bash script.sh बिना execute permission के भी काम करता है, क्योंकि आप explicitly bash को invoke कर रहे हैं।

उदाहरण: Running Scripts

bash
# Run with the interpreter directly
bash script.sh

# Or make it executable and run it directly
chmod +x script.sh
./script.sh

⚠️ Run this in your own terminal or Node.js environment.

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. hello.sh को बिना ./ के run करना, इसलिए shell PATH में देखता है और current directory में मौजूद script के लिए command not found report करता है।
  2. ./hello.sh को बिना execute permission के run करना, जो Permission denied देता है; chmod +x या bash hello.sh उपयोग करें।
  3. एक script को sh script.sh से run करना और Bash features की उम्मीद करना, क्योंकि sh एक simpler shell हो सकता है।

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.