Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • However, echo $(var=$((1+2+3)); echo $var) does echo a 6. Commented Jun 7, 2022 at 15:38
  • @done, yes, because var gets assigned the value 6, and the stuff inside the command substitution runs in a single subshell, so the variable keeps that value for the duration of that subshell, if one wants to make a convoluted command substitution like that. None of that contradicts anything I said here, though. Commented Jun 7, 2022 at 19:06
  • None of that contradicts anything I said here, though. .... Well, maybe, but there is an Arithmetic expansion occurring after a command substitution has been parsed, isn't it? Commented Jun 7, 2022 at 20:58
  • @done, you don't need the temporary variable for that, you can do just $(echo $((a+b)) ) or $(( $(somecmd) + 3)). Nested expansions work fine. What I wrote above was about the results of the expansions being scanned for further expansions, that doesn't happen, the same way the shell doesn't scan the results of expansions for operators like |. That was what the question was about anyway. Commented Jun 7, 2022 at 21:09