[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash syntax



* 2021-07-30 07:41:23-0400, Greg Wooledge wrote:

> On Fri, Jul 30, 2021 at 08:48:28AM +0300, Teemu Likonen wrote:
>> You have already got answers but here is another. Bash has a special
>> arithmetic evaluation mode which happens in:
>> 
>>     let ...          # returns true (0) or false (1)
>>     (( ... ))        # returns true (0) or false (1)
>>     $(( ... ))       # returns the value of the expression
>
> The word "returns" is a bit misleading in the last case.  It doesn't
> set the exit status (as seen in the $? special parameter) to the
> value of the expression the way the first two set it to 0 or 1.
>
> The last one is a substitution, meaning it's *replaced* inline by the
> value of the expression.

Indeed, that is very good correction. In normal programming languages an
expression is evaluated and it returns something. In Bash there are two
different things: commands' return values (exit status) and many
different expansions. So let us correct:

    let ...          # returns true (0) or false (1)
    (( ... ))        # returns true (0) or false (1)
    $(( ... ))       # expands to the value of the expression

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

Attachment: signature.asc
Description: PGP signature


Reply to: