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

Variable की Basics

एक variable एक jar पर sticky-note label जैसा है जो कुछ ऐसा रखता है जिसे आप याद रखना चाहते हैं। आप नाम एक बार लिखते हैं और फिर जब भी आपको अंदर की चीज़ चाहिए उसे उपयोग करते हैं।

In this page:

  1. Variable Basics
Syntax
bash
variable_name=value
echo "$variable_name"

Variable Basics

Bash variables name=value से assign होते हैं और = के आसपास कोई spaces नहीं। आप एक variable की value $ prefix करके पढ़ते हैं, जैसे $name।

Bash के पास कोई static types नहीं हैं — हर variable internally एक string के रूप में stored है, भले ही यह numeric जैसा कुछ रखता हो।

Warning: name = value (spaces के साथ) एक syntax error है — Bash इसे name नाम का एक command run करने की कोशिश के रूप में interpret करता है।

उदाहरण: Variable Basics

bash
#!/bin/bash
name="Alice"
age=30

echo "Name: $name"
echo "Age: $age"
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. Equals sign के आसपास spaces लगाना, जैसे name = "Ada", जिसे Bash name नाम के एक command के रूप में पढ़ता है।
  2. Left side पर $ उपयोग करना, जैसे $name="Ada", जो एक error है।
  3. एक variable पढ़ते समय $ भूल जाना, इसलिए echo name शब्द name print करता है।

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.