Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16603
| From | Lawrence Velázquez <vq@larryv.me> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Integer (re)declaration keeps string values |
| Date | 2020-07-22 04:48 -0400 |
| Message-ID | <mailman.318.1595407719.24492.bug-bash@gnu.org> (permalink) |
| References | <courier.000000005F17F4DE.000F3004@charon.podzimek.org> <6B0FBD2F-3194-4642-8F72-929778D0AE79@larryv.me> |
> 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
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Integer (re)declaration keeps string values Lawrence Velázquez <vq@larryv.me> - 2020-07-22 04:48 -0400
csiph-web