help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Arithmetic evaluation / expansion question


From: Bruce Hohl
Subject: Re: [Help-bash] Arithmetic evaluation / expansion question
Date: Thu, 11 Oct 2018 01:23:04 +0000

@Quentin
Light bulb!  I understand now.  Thanks!


On Thu, Oct 11, 2018 at 12:46 AM Quentin L'Hours <address@hidden>
wrote:

> On 2018-10-10 05:36 PM, Bruce Hohl wrote:
> >> In an arithmetic context, pd is evaluated identically to $pd ...
> > I do understand that as it is described in the man page.  For arithmetic
> > evaluation, the man page also indicates that null or unset variables
> > evaluate to zero.
> >
> > I have noted through "observation" (per the original example) that a
> > defined variable which holds a string not beginning with zero (non-octal)
> > also is "arithmetically" evaluated to zero.  Is that behavior as
> intended?
> > I.E. can that behavior be relied upon?  I admit I did not read the entire
> > man page. ;)
>
> I think you're misunderstanding what is actually going on, it evaluates
> to zero because of the recursive behavior described by Greg and Andy,
> not because it contains something not beginning with zero:
>
> When doing $((pd)) in your example, here's what happens:
> - pd is evaluated to abc
> - abc is unset so it is evaluated to 0
>
> As simple as that.
> if abc was set to 2, then $((pd)) would expand to 2.
>
> That's also what is happening in Greg's example:
> wooledg:~$ a=b b=c c=d d=e e=f f=42; echo $((a))
> 42
>
> Hope this is a bit clearer.
>
>


reply via email to

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