help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] declare -i


From: Bill Gradwohl
Subject: Re: [Help-bash] declare -i
Date: Wed, 9 May 2012 14:43:31 -0600

On Wed, May 9, 2012 at 1:49 PM, Greg Wooledge <address@hidden> wrote:
You're aware of this issue, right?

imadev:~$ unset intArray
imadev:~$ declare -i -a intArray
imadev:~$ xyz=42
imadev:~$ intArray=(5 2 1 -19 xyz)
imadev:~$ declare -i -a
declare -ai intArray='([0]="5" [1]="2" [2]="1" [3]="-19" [4]="42")'

Just making sure.

Nope. Wasn't aware of it. Thank You for the education.

Now I have to try to explain this to myself as to why it works. Here goes.

Everything is considered in an arithmetic context because of the -i. Variables inside an arithmetic context don't need the $ or ${}, so that's why it works. ???

If that's the case, then putting 'xyz' into an arithmetic context should have produced a 0 but it didn't. Therefore my analysis must be wrong.

All this while I assumed that -i was doing efficient things behind the scenes using binaries to hold integers. Now I realize that -i doesn't do anything of the sort and actually adds overhead. I conclude -i isn't worth using unless the side effects are what you want.

--
Bill Gradwohl


reply via email to

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