← Back to Bash Course | Chapter 4: Loops | Lesson 5 of 14

let कमांड

let एक helper को यह कहने जैसा है 'इसे work out करो और answer मेरे label पर लिख दो'। आप इसे एक छोटा sum देते हैं और यह result एक variable में store कर देता है।

In this page:

  1. let
Syntax
bash
let variable=expression

let

let एक arithmetic expression के result को evaluate और assign करता है एक variable को, $(( )) जैसा ही लेकिन एक standalone command के रूप में। let x=5+3 x को 8 set करता है बिना right-hand side पर $ की ज़रूरत के।

यह एक पुराना alternative है जो आज $(( )) या ((...)) से कम commonly उपयोग होता है।

Note: ((x = 5 + 3)) let x=5+3 का modern equivalent है और generally preferred है।

उदाहरण: let

bash
#!/bin/bash
let x=5+3
echo "x = $x"

let "y = x * 2"
echo "y = $y"
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. let उपयोग करते समय = के आस-पास spaces लगाना, जैसे let x = 5, जो fail होता है जब तक expression quoted न हो।
  2. let से decimals के साथ काम करने की उम्मीद करना, जब यह integer only है।
  3. let उपयोग करना और यह भूल जाना कि 0 result exit status 1 देता है, जो set -e के साथ एक script को रोक सकता है।

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.