[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Order of command substitution and arithmetic expansion
From: |
Lawrence Velázquez |
Subject: |
Re: Order of command substitution and arithmetic expansion |
Date: |
Sat, 13 Nov 2021 16:48:16 -0500 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-1371-g2296cc3491-fm-20211109.003-g2296cc34 |
On Sat, Nov 13, 2021, at 2:36 PM, Greg Wooledge wrote:
> So we're left with (b) it goes left to right.
To elaborate a little on what Greg said: Here is the full sentence
from the manual, which you only quoted partially.
The order of expansions is: brace expansion; tilde expansion,
parameter and variable expansion, arithmetic expansion, and
command substitution (done in a left-to-right fashion); word
splitting; and filename expansion.
The semicolons and colons are not distributed arbitrarily. You can
think of the sentence as describing the following "precedence":
1. Brace expansion.
2. Tilde expansion, parameter and variable expansion, arithmetic
expansion, command substitution. These are performed from
left to right.
3. Word splitting.
4. Filename expansion.
The expansions in #2 all have the same "precedence"; the order in
which they are listed doesn't really mean anything. Observe that,
for instance, a parameter expansion can occur after an arithmetic
expansion:
$ i=7
$ echo "$((i++))" "$i"
7 8
--
vq