What is Shell Scripting?

What is Shell Scripting?

A shell script is a simple text file that contains commands.
These commands are written in a sequence and are run by the Linux Shell.
Think of it like a recipe – one step after another!

Shell scripting is used to automate tasks.


📌 What is a Shell?

  • A shell is a program in Linux.
  • It takes input from the user.
  • It gives that input to the Operating System (OS).
  • Then, it shows the output.

🧠 Memory Trick:
Shell = Middleman between User and OS.


✅ Uses of Shell Scripting:

  1. Automate daily tasks
  2. Run many commands together
  3. Backup files
  4. Manage systems
  5. Install software
  6. Check system health

📄 Simple Example:

!/bin/bash

echo “Hello Gopal!”

This script will simply print:
Hello Gopal!

📚 Popular Shells in Linux:

Shell NameDescription
BashMost common shell
ShOriginal shell
ZshAdvanced features
CshC language style

🛠️ Basic Shell Script Commands:

CommandPurpose
echoPrint message
readTake user input
ifCondition checking
forLoop (repeat tasks)
whileAnother type of loop

🧪 Sample Script for Adding Numbers:

#!/bin/bash
echo "Enter 2 numbers:"
read a
read b
sum=$((a + b))
echo "Sum is: $sum"

✅ Advantages of Shell Scripting:

Saves time

Automates tasks

Easy to write

Lightweight

Reusable code

❌ Disadvantages:

Limited GUI (mostly text)

Syntax errors are common

Slower than compiled languages like C

Not very secure if not written properly

📝 Exam Format – How to Write in Exam

Q: What is Shell Scripting? Explain with advantages and example.

Ans:
Shell scripting is a process of writing commands in a file so they can run automatically by the shell. It helps in task automation.

Example:
#!/bin/bash
echo "Hello World"

🧠 Mind Map (Text Format)

Shell Scripting
├── What is Shell
├── Uses
│ ├── Automate tasks
│ ├── Run multiple commands
├── Types of Shell
│ ├── Bash
│ ├── Sh
│ ├── Zsh
├── Basic Commands
│ ├── echo
│ ├── read
│ ├── if, for, while
├── Examples
├── Advantages
├── Disadvantages


🔰 शेल स्क्रिप्टिंग क्या होती है?

शेल स्क्रिप्टिंग एक टेक्स्ट फ़ाइल होती है जिसमें कई कमांड्स लिखी जाती हैं।
इन कमांड्स को एक के बाद एक Linux Shell द्वारा चलाया जाता है।

🔁 मतलब:
जो काम रोज़-रोज़ करते हो, उसे स्क्रिप्ट में लिख दो — काम ऑटोमैटिक हो जाएगा।


📌 शेल (Shell) क्या होता है?

  • शेल एक प्रोग्राम होता है।
  • ये यूज़र का इनपुट लेता है
  • उसे ऑपरेटिंग सिस्टम तक पहुँचाता है।
  • फिर आउटपुट दिखाता है।

🧠 याद करने का ट्रिक:
Shell = User और OS के बीच पुल (Bridge)


✅ शेल स्क्रिप्टिंग के उपयोग:

  1. रोज़ के काम ऑटोमैटिक करने में
  2. एक साथ कई कमांड्स चलाने में
  3. बैकअप बनाने में
  4. सिस्टम को मैनेज करने में
  5. सॉफ्टवेयर इंस्टॉल करने में
  6. हेल्थ चेकअप (Disk, RAM आदि) में

📄 एक सिंपल उदाहरण:

!/bin/bash

echo “Hello Gopal!”

⏩ यह स्क्रिप्ट बस एक मैसेज दिखाएगी:
Hello Gopal!

📚 Linux में लोकप्रिय Shells:

Shell का नामविशेषता
Bashसबसे ज्यादा इस्तेमाल होने वाला
Shसबसे पुराना Shell
ZshAdvance features वाला
CshC language जैसा style

🛠️ कुछ बेसिक कमांड्स:

कमांडकाम
echoमैसेज दिखाना
readयूज़र से इनपुट लेना
ifकंडीशन चेक करना
forलूप चलाना
whileबार-बार चलाने के लिए

🧪 दो नंबर जोड़ने वाली स्क्रिप्ट:

!/bin/bash

echo “दो नंबर दर्ज करें:”
read a
read b
sum=$((a + b))
echo “योग है: $sum”

✅ शेल स्क्रिप्टिंग के लाभ:

  • समय की बचत
  • काम को ऑटोमैटिक कर देती है
  • लिखने में आसान
  • हल्का (Lightweight)
  • एक बार लिखा – बार-बार इस्तेमाल

❌ नुकसान:

  • GUI नहीं होता (text-based)
  • सिंटैक्स में गलती हो सकती है
  • Compiled language से थोड़ा धीमा
  • सिक्योरिटी के खतरे (अगर ध्यान न रखा जाए)

📝 परीक्षा के लिए उत्तर कैसे लिखें?

प्रश्न: शेल स्क्रिप्टिंग क्या है? उदाहरण और लाभ सहित समझाइए।

उत्तर:
शेल स्क्रिप्टिंग एक प्रक्रिया है जिसमें हम कमांड्स को एक फाइल में लिखते हैं ताकि वे shell द्वारा एक साथ चलाई जा सकें। यह काम को ऑटोमैटिक करने में मदद करती है।

उदाहरण:

#!/bin/bash  
echo "Hello World"

लाभ:

  1. समय की बचत
  2. बार-बार के काम आसान
  3. सिंपल और लाइटवेट
  4. कोड दोबारा इस्तेमाल किया जा सकता है
  5. आसानी से डिबग कर सकते हैं

🧠 माइंड मैप (Text में)

Shell Scripting
├── शेल क्या है
├── उपयोग
│ ├── ऑटोमेशन
│ ├── बैकअप
├── शेल के प्रकार
│ ├── Bash
│ ├── Zsh
├── बेसिक कमांड्स
│ ├── echo, read
│ ├── if, for
├── उदाहरण
├── लाभ
├── नुकसान

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *