Quoting के नियम
Quotes computer को बताते हैं कि आपके words कितनी carefully पढ़ें। Double quotes इसे आपके labels की values swap करने देते हैं, जबकि single quotes कहते हैं 'इसे exactly जैसा लिखा है वैसे ही पढ़ो, कोई swapping नहीं'।
In this page:
Syntax
echo "double quotes expand: $variable"
echo 'single quotes are literal: $variable'
Quoting Rules
Double quotes ("...") इनके अंदर variable expansion और command substitution allow करते हैं, जबकि single quotes ('...') सब कुछ literally treat करते हैं, $ सहित।
Unquoted variables shell द्वारा word-split और glob-expand होते हैं, जो values में spaces होने पर bugs cause कर सकता है। Variables को consistently quote करना सबसे important Bash habits में से एक है।
Note:
जिन variables को आप expand करें उन्हें हमेशा quote करें, जैसे
"$name", जब तक आप specifically word-splitting न चाहें।उदाहरण: Quoting Rules
#!/bin/bash
name="Bob Smith"
echo "Double quotes: $name"
echo 'Single quotes: $name'
echo Unquoted: $name
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. #}
आम गलतियां
- Single quotes उपयोग करना और variable expansion की उम्मीद करना, क्योंकि
'$name'literally$nameprint करता है। - Variables को unquoted छोड़ना, इसलिए spaces वाली एक value कई words में split हो जाती है।
- Escape किए बिना एक जैसी quotes nest करना, जो string को जल्दी end कर देता है।
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: