[Top][All Lists]

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

Re: hi, this is student studying bash. (typeset question)

From: Greg Wooledge
Subject: Re: hi, this is student studying bash. (typeset question)
Date: Tue, 29 Sep 2020 07:42:40 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Tue, Sep 29, 2020 at 12:40:36PM +0900, wrote:
> Dear gnu team.
> hi, I'm studying embedded system and bash these days.
> but little confusing about type system.
> where is integer type definition code?

Even when a variable is declared with the -i flag, it is not *stored*
as an integer.  It's still stored as a string, just with this additional
flag attached to it.

> I read linux documentation project's docs.
> doc1.
> doc2.
> doc3.

The "abs" is considered a rather poor source of information.  It contains
many errors.

> Integer variables in older versions of Bash were signed long (32-bit)
> integers, in the range of -2147483648 to 2147483647. An operation that took
> a variable outside these limits gave an erroneous result.

What you're talking about here applies to integer *arithmetic* performed
by bash, and it's partially correct.  When bash does integer arithmetic,
it uses signed variables, of type intmax_t (formerly long, as you said,
but that was before version 2.05b).

Basically, any time there is arithmetic to be done, the following happens:

1) All the strings get converted to numbers by recursive expansion.  If
   a given string contains only digits (and optional leading +/- sign),
   it gets converted to intmax_t and this piece of the recursive
   expansion is done.  Otherwise, if the string contains something
   which is a valid shell variable name, it's treated as a variable,
   and that variable's value is expanded as an arithmetic expression.
   A shell variable with an empty value (or an unset variable) is treated
   as zero in this context.

2) The desired arithmetic operations are performed on the internal intmax_t

3) The final result is converted to a string, to be used wherever the
   result of the arithmetic is needed.

> the question is
> <strong> where can I find integer type definition code? <strong>

That part, I do not know.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]