BCA / B.Tech 10 min read

Array in Hindi OS

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: Array in Hindi OS - General Topics
  • • अवलोकन: Quick Answer: Linux और Operating System के Bash Shell Scripting में Array एक विशेष प्रकार का variable है जो एक ही नाम के तहत कई मानों (elements) को stor...
  • • मुख्य अवधारणाएं: Array in OS, Declaration indexing loops Hindi, Multidimensional arrays OS,Array in OS, Declaration indexing loops, Multidimensional arrays OS
Quick Answer: Linux और Operating System के Bash Shell Scripting में Array एक विशेष प्रकार का variable है जो एक ही नाम के तहत कई मानों (elements) को store करता है। इसे arr=(val1 val2 val3) सिंटैक्स से बनाया जाता है। पहले element को ${arr[0]} से, सभी elements को ${arr[@]} से और array की कुल लंबाई को ${#arr[@]} से प्राप्त किया जाता है। Bash 4.0+ में Associative Arrays (key-value pairs) का भी पूरा सपोर्ट है।

Linux Shell Scripting में Array क्या है?

operating system (विशेषकर Unix/Linux) में system एडमिनिस्ट्रेटर और डेवलपर्स ऑटोमेशन टास्क के लिए Shell Scripts लिखते हैं। जब हमें कई server IP addresses, file नामों या user एकाउंट्स की लिस्ट को एक साथ प्रोसेस करना होता है, तो अलग-अलग variables बनाने के बजाय Array का use किया जाता है।

Linux के बेसिक कमांड्स सीखने के लिए पढ़ें: Commands of Linux in Hindi। operating system के रूप में Linux के architecture को समझने के लिए देखें: Linux in Hindi।

Advertisement

Bash में Array के प्रकार (Types of Arrays)

Linux Bash Shell में मुख्य रूप से दो प्रकार के arrays होते हैं:

1. Indexed Array (Indexed Array)

यह default array है जिसमें हर element को 0 से शुरू होने वाला एक संख्यात्मक (numeric) index नंबर मिलता है। उदाहरण: os=("Ubuntu" "RedHat" "Debian")। यहाँ os[0] का मान Ubuntu है।

2. Associative Array (Associative Array)

Bash version 4.0 और उसके बाद के संस्करणों में कस्टम स्ट्रिंग keys का सपोर्ट जोड़ा गया। इसे बनाने से पहले declare -A कमांड से घोषित करना अनिवार्य होता है। उदाहरण: declare -A user_id=([rahul]=101 [priya]=102)।

Table 1: Indexed Array vs Associative Array

तुलना का बिंदु Indexed Array Associative Array
Declaration साधारण असाइनमेंट: arr=(a b c) स्पष्ट डिक्लेरेशन ज़रूरी: declare -A arr
Index Type केवल 0 या उससे बड़े integer (0, 1, 2, 3...) टेक्स्ट या स्ट्रिंग keys (जैसे [name], [city])
Bash Version सभी Bash वर्जन्स में सपोर्टेड Bash 4.0 और नए वर्जन्स में ही उपलब्ध
Data Access ${arr[0]} ${arr["name"]}
Best Use Case क्रमबद्ध files या नंबर्स की लिस्ट डिक्शनरी, कॉन्फ़िगरेशन settings और मैपिंग

Bash Array के मूल सिंटैक्स और ऑपरेशंस

# 1. Declaration (घोषणा)
distros=("Ubuntu" "CentOS" "Fedora" "Arch")

# 2. Access Single Element (पहला element)
echo ${distros[0]}      # Output: Ubuntu

# 3. Access All Elements (सभी elements)
echo ${distros[@]}      # Output: Ubuntu CentOS Fedora Arch

# 4. Total Number of Elements (कुल लंबाई)
echo ${#distros[@]}     # Output: 4

# 5. Add / Append new element (नया तत्व जोड़ना)
distros+=("Debian")

# 6. Delete an element (हटाना)
unset distros[1]        # CentOS हट जाएगा

# 7. Array Slicing (हिस्सा काटना: index 1 से 2 elements)
echo ${distros[@]:1:2}  # Output: Fedora Arch (index 1 अब खाली है, इसलिए index 2 से शुरू)

Table 2: Bash Shell Array Operations Cheat Sheet

ऑपरेशन Bash सिंटैक्स उदाहरण परिणाम / अर्थ
Create Array arr=(v1 v2 v3) ports=(22 80 443) 3 elements का array बना
Get Element ${arr[index]} echo ${ports[1]} 80 (दूसरा तत्व)
All Elements ${arr[@]} echo ${ports[@]} 22 80 443
Array Length ${#arr[@]} echo ${#ports[@]} 3 (elements की कुल संख्या)
Element Length ${#arr[i]} echo ${#ports[2]} 3 (443 में 3 डिजिट्स हैं)
All Keys / Indices ${!arr[@]} echo ${!ports[@]} 0 1 2 (सभी indices की सूची)
Append Element arr+=(new_val) ports+=(8080) अंत में 8080 जुड़ गया
Delete Element unset arr[i] unset ports[0] Port 22 हट गया

Solved Example: Linux Bash Shell Script में Array का उपयोग

नीचे दी गई व्यावहारिक shell script दर्शाती है कि कैसे servers की एक array बनाकर loop से प्रत्येक server का स्टेटस चेक किया जाता है:

#!/bin/bash
# Script: server_check.sh
# उद्देश्य: Array और Loop का व्यावहारिक उपयोग

# 1. Servers का Array घोषित करना
servers=("Web_Server_1" "Database_Master" "Backup_Node" "Cache_Redis")

echo "=========================================="
echo "कुल मॉनिटर किए जाने वाले servers: ${#servers[@]}"
echo "=========================================="

# 2. नया server जोड़ना (Append)
servers+=("Mail_Server")

# 3. For loop से सभी servers को प्रोसेस करना
index=1
for server in "${servers[@]}"; do
    echo "Checking Server #$index: $server ... [ONLINE]"
    ((index++))
done

# 4. किसी पुराने server को हटाना (Remove element)
unset servers[2] # Backup_Node हटा दिया

echo ""
echo "अपडेटेड servers की सूची:"
for server in "${servers[@]}"; do
    echo "-> Active: $server"
done

टर्मिनल पर Real Script Output:

==========================================
कुल मॉनिटर किए जाने वाले servers: 4
==========================================
Checking Server #1: Web_Server_1 ... [ONLINE]
Checking Server #2: Database_Master ... [ONLINE]
Checking Server #3: Backup_Node ... [ONLINE]
Checking Server #4: Cache_Redis ... [ONLINE]
Checking Server #5: Mail_Server ... [ONLINE]

अपडेटेड servers की सूची:
-> Active: Web_Server_1
-> Active: Database_Master
-> Active: Cache_Redis
-> Active: Mail_Server
Advertisement

Shell Scripting में Array से संबंधित सावधानियां (Common Mistakes)

  • बराबर के दोनों तरफ स्पेस देना: Bash में arr = (1 2 3) लिखने पर सिंटैक्स error आता है। हमेशा बिना स्पेस के arr=(1 2 3) लिखें।
  • Double Quotes न लगाना: Loop में हमेशा "${arr[@]}" का उपयोग करें। यदि elements में स्पेस होगा (जैसे "Server One"), तो बिना quotes के Bash उसे दो अलग-अलग elements मान लेगा।
  • ${arr} लिखना: यदि आप सिर्फ $arr या ${arr} लिखेंगे, तो Bash केवल पहले element (इंडेक्स 0) को प्रिंट करेगा, पूरा array नहीं।

Exam के लिए Important Questions

Short Questions (2–3 marks)

  1. Bash Shell में Array की कुल लंबाई कैसे प्राप्त की जाती है?
    (उत्तर: ${#array_name[@]} सिंटैक्स का उपयोग करके।)
  2. Linux में Associative Array घोषित करने के लिए कौन-सा कीवर्ड अनिवार्य है?
    (उत्तर: declare -A कमांड।)
  3. ${arr[@]} और ${arr[*]} में क्या अंतर है?
    (उत्तर: Double quotes के अंदर "${arr[@]}" प्रत्येक तत्व को अलग शब्द मानता है, जबकि "${arr[*]}" सभी को मिलाकर एक सिंगल स्ट्रिंग बनाता है।)
  4. Bash में array के किसी element को हटाने के लिए किस कमांड का उपयोग होता है?
    (उत्तर: unset array_name[index] का।)

Long Questions (5–10 marks)

  1. Linux Shell Scripting में Array क्या है? Indexed Array और Associative Array के निर्माण और संचालन को उदाहरण के साथ समझाइए। (10 marks)
  2. Bash Array के प्रमुख ऑपरेशंस (Append, Slice, Delete, Length) को उनके सिंटैक्स और एक पूर्ण शेल स्क्रिप्ट उदाहरण के साथ स्पष्ट कीजिए। (10 marks)
  3. Linux operating system में shell scripting के फायदे और array के use के परिदृश्यों पर टिप्पणी लिखिए। (5 marks)

FAQs

क्या Bash Array में अलग-अलग data टाइप्स (Numbers और Strings) मिक्स किए जा सकते हैं?

हाँ, Bash Array में data टाइप की सख्त बाध्यता नहीं होती। आप एक ही array में my_arr=(100 "Ubuntu" 45.5 "Admin") जैसे नंबर और स्ट्रिंग दोनों स्टोर कर सकते हैं।

क्या Bash में बहु-आयामी (2D / Multidimensional) Arrays सपोर्ट होते हैं?

Bash मूल रूप से 2D arrays को सीधे सपोर्ट नहीं करता। डेवलपर इसके लिए या तो 1D array में इंडेक्स formula $((row * cols + col)) का उपयोग करते हैं या Associative Array में matrix["0,1"] जैसी कंपोजिट कीज़ बनाते हैं।

unset करने के बाद क्या Array के बाकी इंडेक्स अपने आप री-ऑर्डर होते हैं?

नहीं, Bash में unset arr[1] करने पर केवल इंडेक्स 1 डिलीट होता है, इंडेक्स 2 अपने आप इंडेक्स 1 नहीं बनता। इसे sparse array कहते हैं।

Linux में read -a कमांड का क्या काम है?

read -a my_arr कमांड user से कीबोर्ड से स्पेस देकर टाइप किए गए कई शब्दों को एक ही बार में array के अलग-अलग elements में स्टोर कर लेती है।

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: Linux और Operating System के Bash Shell Scripting में Array एक विशेष प्रकार का variable है जो एक ही नाम के तहत।
Operating System (OS) Notes in Hindi | ऑपरेटिंग सिस्टम नोट्स के पाठ्यक्रम में Array in Hindi OS एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको Array in Hindi OS के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

Array in Hindi OS
Distributed System in Hindi
Real Time System in Hindi
System Calls in Hindi
System Program in Hindi
Structure of Operating System in Hindi
Layers Design of Structure in Hindi
Unix in Hindi
Virtual Machine in Hindi
Kernel-Based Operating System in Hindi
Process in Hindi – OS में Process क्या है
Interacting Processes in Hindi
Threads in Hindi
Fundamental of Schedulling in Hindi
Scheduling Criteria in Hindi
Long Medium Short Term Scheduling in Hindi
Scheduling Algorithms in Hindi
Structure of Concurrent System in Hindi
Critical Region in Hindi
Critical Section in Hindi
Inter process Communication in Hindi
Monitor in Hindi
Semaphore in OS in Hindi – Counting और Binary Semaphore
Semaphores Implementation & Uses in Hindi
Logical and Physical Address in Hindi
Swapping in Hindi
Contiguous Allocation in Hindi
Segmentation in Hindi
Paging in OS in Hindi – Paging और Segmentation
Paging with Segmentation in Hindi
kernel Memory Allocation in Hindi
Page Replacement Algorithms in Hindi
Virtual Memory in Hindi
Virtual Memory with demand Paging in Hindi
Deadlock & Characterization in Hindi
Methods for Handling Deadlocks in Hindi
Deadlock Thrashing in Hindi
Allocation of Frames in Hindi
Virtual Memory using Segmentation in Hindi
Interprocess Communication protocol in Hindi
Network Operating System in Hindi
Design Issues in Distributed File System in Hindi
Network Structure in Hindi
Structure Distributed System in Hindi
File System and Coordination in Hindi
Linux in Hindi
Commands of Linux in Hindi | लिनक्स के कमांड्स हिंदी में
Programmer Interface & File manipulation in Hindi
Process control in Linux in Hindi
Linux Kernel & Signals in Hindi
File System in Linux in Hindi
block & inodes in Hindi
System Editor in Hindi
Character Transliteration in Hindi
ED in Hindi
Vi Editor & There Commands in Hindi
Shell Script in Hindi
Looping & Decision Making in Hindi
Variables & File name Expansion in Hindi
Sub Program in Hindi
C interface with Linux in Hindi
Simpel Shell Programs in Hindi
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is Operating System (OS) in Hindi
Operating System (OS) All Important Questions and Answers in Hindi (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Type of Operating System in Hindi
Goals of Operating System in Hindi
Operation of Operating system in Hindi
Resource Allocation & Functions in Hindi
class of Operating system in Hindi
Batch Processing in Hindi
Multi Processing in Hindi
Time Sharing in Hindi