bug-bash
[Top][All Lists]
Advanced

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

Re: Integer (re)declaration keeps string values


From: Lawrence Velázquez
Subject: Re: Integer (re)declaration keeps string values
Date: Wed, 22 Jul 2020 04:48:30 -0400

> On Jul 22, 2020, at 4:12 AM, andrej--- via Bug reports for the GNU
> Bourne Again SHell <bug-bash@gnu.org> wrote:
> 
> Description:
>       Integer variables don't get (re)parsed when (re)declared.
> 
> Repeat-By:
>       a=z
>        declare -i a
>        echo $a  # z (I'd expect emptiness or 0)

The man page explicitly says that arithmetic evaluation is performed
*on assignment*.

    -i  The variable is treated as an integer; arithmetic evaluation
        (see ARITHMETIC EVALUATION above) is performed when the
        variable is assigned a value.

Sure enough:

    % bash
    bash-5.0$ a=z
    bash-5.0$ declare -i a
    bash-5.0$ echo "$a"
    z
    bash-5.0$ a=z
    bash-5.0$ echo "$a"
    0

vq



reply via email to

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