← Back to Bash Course | Chapter 3: Control Flow | Lesson 1 of 14

read कमांड

read एक question पूछने और किसी के जवाब देने का इंतज़ार करने जैसा है। Script रुक जाता है, व्यक्ति को एक reply type करने देता है, और उस reply को एक labeled jar में डाल देता है।

In this page:

  1. The read Command
Syntax
bash
read [-p "prompt"] variable_name

The read Command

read एक script को pause करता है और user द्वारा input type करने का इंतज़ार करता है, इसे एक variable में store करते हुए। read -p "prompt" इंतज़ार करने से पहले एक prompt दिखाता है। यह एक interactive script बनाने का standard तरीका है जो user input पर respond करता है।

Note: read -s उपयोग करें input को silently पढ़ने के लिए, जैसे जब password के लिए prompt कर रहे हों।

उदाहरण: The read Command

bash
#!/bin/bash
echo "Simulating input via echo pipe since this runs non-interactively:"
name="Guest"
echo "Hello, $name! (in an interactive terminal, 'read -p \"Name: \" name' would prompt you)"
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. -r भूल जाना, इसलिए input में backslashes को escapes के रूप में treat किया जाता है।
  2. एक variable में बिना इसे बाद में quote किए पढ़ना, इसलिए spaces split हो जाते हैं।
  3. यह उम्मीद करना कि एक piped while loop के अंदर read loop के बाद variables रखेगा, जब pipeline एक subshell में चलता है।

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.