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

आपकी पहली Script

आपकी पहली script अपनी पहली तीन-step recipe लिखने जैसी है: top पर एक label, कुछ instructions, और यह याद रखने के लिए notes कि क्यों। इसे save करें, run करें, और computer को साथ follow करते देखें।

In this page:

  1. Your First Script
Syntax
bash
#!/bin/bash
# describe what the script does
variable_name="value"
echo "message with $variable_name"

Your First Script

एक complete पहली script shebang, कुछ commands, और intent explain करने वाले comments को combine करती है। इसे .sh extension के साथ save करना एक convention है, requirement नहीं — Bash file extensions की care नहीं करता।

जो मायने रखता है वह है shebang line और execute permission।

Note: अपनी पहली scripts छोटी रखें और उन्हें बहुत सारे commands लिखने से पहले बार-बार test करें, run करने से पहले नहीं।

उदाहरण: Your First Script

bash
#!/bin/bash
# My first Bash script
echo "Starting script..."
name="World"
echo "Hello, $name!"
echo "Script finished."
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. Script के top पर #!/bin/bash line भूल जाना।
  2. Script को executable बनाना भूल जाना, फिर Permission denied मिलना।
  3. Script के अंदर एक relative path उपयोग करना और इसे किसी और directory से run करना, इसलिए files नहीं मिलतीं।

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.