Timeline for Bash: Arithmetic expansion, parameter expansion, and the comma operator
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 14, 2020 at 5:09 | history | edited | Mitchell Spector | CC BY-SA 4.0 |
Fixes from prior edit: "subexpression" is a perfectly good word, and subtitles can start with a capital letter.
|
| Mar 10, 2020 at 15:16 | vote | accept | Mitchell Spector | ||
| Mar 10, 2020 at 11:09 | comment | added | ilkkachu |
Similarly, this gives an error: i=3; echo $(( $i++ )) (since 3++ doesn't make sense)
|
|
| Mar 10, 2020 at 10:10 | history | edited | Paulo Tomé | CC BY-SA 4.0 |
Formatted text. Grammar. Spelling.
|
| Mar 10, 2020 at 10:07 | answer | added | Stéphane Chazelas | timeline score: 3 | |
| Mar 10, 2020 at 10:01 | answer | added | Stephen Kitt | timeline score: 3 | |
| Mar 10, 2020 at 10:00 | comment | added | Mitchell Spector | @AdminBee Thank you, that makes sense. It’s too late here today, but I’ll test it with some other examples tomorrow, now that I know what kind of thing to try. | |
| Mar 10, 2020 at 9:57 | comment | added | AdminBee |
I think the point here is "parameter expansion is performed before the expression is evaluated". I understand this as $((n++,k=$n)) is first expanded to $((n++,k=3)) (i.e. you "force" parameter expansion) and then evaluated arithmetically, leaving n to be 4, but k still at 3. When no parameter expansion is necessary (no $ inside the expression), only the $((n++,k=n)) arithmetic evaluation is performed as per left-to-right order.
|
|
| Mar 10, 2020 at 9:50 | review | First posts | |||
| Mar 10, 2020 at 10:10 | |||||
| Mar 10, 2020 at 9:45 | history | asked | Mitchell Spector | CC BY-SA 4.0 |