← Back to Bash Course | Chapter 2: Variables & Types | Lesson 3 of 13

Quoting के नियम

Quotes computer को बताते हैं कि आपके words कितनी carefully पढ़ें। Double quotes इसे आपके labels की values swap करने देते हैं, जबकि single quotes कहते हैं 'इसे exactly जैसा लिखा है वैसे ही पढ़ो, कोई swapping नहीं'।

In this page:

  1. Quoting Rules
Syntax
bash
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

bash
#!/bin/bash
name="Bob Smith"

echo "Double quotes: $name"
echo 'Single quotes: $name'
echo Unquoted: $name
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. Single quotes उपयोग करना और variable expansion की उम्मीद करना, क्योंकि '$name' literally $name print करता है।
  2. Variables को unquoted छोड़ना, इसलिए spaces वाली एक value कई words में split हो जाती है।
  3. Escape किए बिना एक जैसी quotes nest करना, जो string को जल्दी end कर देता है।

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.