help-bash
[Top][All Lists]
Advanced

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

Re: Order of command substitution and arithmetic expansion


From: Greg Wooledge
Subject: Re: Order of command substitution and arithmetic expansion
Date: Sat, 13 Nov 2021 10:50:35 -0500

On Sat, Nov 13, 2021 at 10:42:54AM -0500, Lawrence Velázquez wrote:
> On Sat, Nov 13, 2021, at 7:48 AM, Dongbo Hu wrote:
> > But I feel that "arithmetic expansion" is done AFTER "command substitution".
> 
> What makes you feel that?

Here is a demonstration showing that arithmetic expansion and
command substitution are performed left-to-right just like the man
page says:

unicorn:~$ i=7
unicorn:~$ : $((i++)) $(declare -p i >&2)
declare -- i="8"

unicorn:~$ i=7
unicorn:~$ : $(declare -p i >&2) $((i++))
declare -- i="7"

If arithmetic expansion happened first in all cases, then the second
result should have been the same as the first result.

If arithmetic expansion happened last in all cases, then the first
result should have been the same as the second result.

The only explanation for the observed results is that it's working as
documented.



reply via email to

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