Variable की Basics
एक variable एक jar पर sticky-note label जैसा है जो कुछ ऐसा रखता है जिसे आप याद रखना चाहते हैं। आप नाम एक बार लिखते हैं और फिर जब भी आपको अंदर की चीज़ चाहिए उसे उपयोग करते हैं।
In this page:
Syntax
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
#!/bin/bash
name="Alice"
age=30
echo "Name: $name"
echo "Age: $age"
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. #}
आम गलतियां
- Equals sign के आसपास spaces लगाना, जैसे
name = "Ada", जिसे Bashnameनाम के एक command के रूप में पढ़ता है। - Left side पर
$उपयोग करना, जैसे$name="Ada", जो एक error है। - एक variable पढ़ते समय
$भूल जाना, इसलिएecho nameशब्दnameprint करता है।
🔒
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: