|
From: | Quentin L'Hours |
Subject: | Re: [Help-bash] Arithmetic evaluation / expansion question |
Date: | Wed, 10 Oct 2018 17:46:31 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |