read कमांड
read एक question पूछने और किसी के जवाब देने का इंतज़ार करने जैसा है। Script रुक जाता है, व्यक्ति को एक reply type करने देता है, और उस reply को एक labeled jar में डाल देता है।
In this page:
Syntax
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
#!/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)"
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
-rभूल जाना, इसलिए input में backslashes को escapes के रूप में treat किया जाता है।- एक variable में बिना इसे बाद में quote किए पढ़ना, इसलिए spaces split हो जाते हैं।
- यह उम्मीद करना कि एक piped
whileloop के अंदरreadloop के बाद variables रखेगा, जब pipeline एक subshell में चलता है।
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: