expr कमांड
expr एक पुराने pocket calculator जैसा है जिसे हर number और sign को spaces से अलग रखने की ज़रूरत होती है इससे पहले कि यह आपको answer दे।
In this page:
Syntax
result=$(expr operand1 operator operand2)
expr
expr एक पुराना external command है जो एक simple arithmetic या string expression evaluate करता है और result print करता है। इसे हर operator और operand के आसपास spaces चाहिए, $(( )) के विपरीत।
ज़्यादातर modern scripts $(( )) या let prefer करते हैं, लेकिन expr अब भी पुराने scripts में दिखता है।
Warning:
expr 1+1 (बिना spaces) 2 के बजाय literally 1+1 print करता है — operators के आसपास spaces mandatory हैं।उदाहरण: expr
#!/bin/bash
result=$(expr 5 + 3)
echo "5 + 3 = $result"
result=$(expr 10 \* 2)
echo "10 * 2 = $result"
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. #}
आम गलतियां
- Operators के आसपास spaces भूल जाना, जैसे
expr 1+2, जो1+2को text के रूप में print करता है। *को unescaped उपयोग करना, जैसेexpr 2 * 3, जिसे shell एक file wildcard के रूप में expand करता है;\*लिखें।- यह उम्मीद करना कि
exprdecimals करेगा, जब यह सिर्फ integers के साथ काम करता है।
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: