Arithmetic Expansion $(( )) का उपयोग
Arithmetic expansion एक built-in calculator जैसा है जो आप किसी भी sentence में drop कर सकते हैं। आप sum को double parentheses में लिखते हैं और answer इसकी जगह ले लेता है।
In this page:
Syntax
result=$(( operand1 operator operand2 ))
Arithmetic Expansion $(( ))
$(( expression )) एक integer arithmetic expression को directly evaluate करता है, operators के आस-पास spaces या किसी external command की ज़रूरत के बिना। यह + - * / % और comparison/logical operators support करता है, सब normal integer math उपयोग करते हुए।
यह Bash में arithmetic करने का standard, modern तरीका है।
Note:
$(( )) सिर्फ integers support करता है — Bash में कोई built-in floating-point arithmetic नहीं है।उदाहरण: Arithmetic Expansion $(( ))
#!/bin/bash
a=10
b=3
echo "Sum: $((a + b))"
echo "Product: $((a * b))"
echo "Integer division: $((a / b))"
echo "Remainder: $((a % b))"
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. #}
आम गलतियां
- एक assignment में
=के आस-पास spaces लगाना, जैसेx = $((1+2))। $(( 5 / 2 ))से2.5मिलने की उम्मीद करना, जब Bash arithmetic integers उपयोग करता है और2देता है।- Non-numeric text पर
$उपयोग करना, जिसे zero माना जाता है या error मिलती है।
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: