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:
- Automate daily tasks
- Run many commands together
- Backup files
- Manage systems
- Install software
- Check system health
📄 Simple Example:
!/bin/bash
echo “Hello Gopal!”
This script will simply print:
Hello Gopal!
📚 Popular Shells in Linux:
Shell Name | Description |
---|---|
Bash | Most common shell |
Sh | Original shell |
Zsh | Advanced features |
Csh | C language style |
🛠️ Basic Shell Script Commands:
Command | Purpose |
---|---|
echo | Print message |
read | Take user input |
if | Condition checking |
for | Loop (repeat tasks) |
while | Another 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)
✅ शेल स्क्रिप्टिंग के उपयोग:
- रोज़ के काम ऑटोमैटिक करने में
- एक साथ कई कमांड्स चलाने में
- बैकअप बनाने में
- सिस्टम को मैनेज करने में
- सॉफ्टवेयर इंस्टॉल करने में
- हेल्थ चेकअप (Disk, RAM आदि) में
📄 एक सिंपल उदाहरण:
!/bin/bash
echo “Hello Gopal!”
⏩ यह स्क्रिप्ट बस एक मैसेज दिखाएगी:
Hello Gopal!
📚 Linux में लोकप्रिय Shells:
Shell का नाम | विशेषता |
---|---|
Bash | सबसे ज्यादा इस्तेमाल होने वाला |
Sh | सबसे पुराना Shell |
Zsh | Advance features वाला |
Csh | C 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"
लाभ:
- समय की बचत
- बार-बार के काम आसान
- सिंपल और लाइटवेट
- कोड दोबारा इस्तेमाल किया जा सकता है
- आसानी से डिबग कर सकते हैं
🧠 माइंड मैप (Text में)
Shell Scripting
├── शेल क्या है
├── उपयोग
│ ├── ऑटोमेशन
│ ├── बैकअप
├── शेल के प्रकार
│ ├── Bash
│ ├── Zsh
├── बेसिक कमांड्स
│ ├── echo, read
│ ├── if, for
├── उदाहरण
├── लाभ
├── नुकसान