Skip to main content
added 28 characters in body
Source Link
choroba
  • 49.6k
  • 7
  • 92
  • 119

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

The manual says the following about arithmetic expansion:

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.

And command substitution is described as

... executing command in a subshell environment

which means all expansions take place when nested from inside out.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

The manual says the following about arithmetic expansion:

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.

And command substitution is described as

... executing command in a subshell environment

which means all expansions take place.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

The manual says the following about arithmetic expansion:

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.

And command substitution is described as

... executing command in a subshell environment

which means all expansions take place when nested from inside out.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 
added 196 characters in body
Source Link
choroba
  • 49.6k
  • 7
  • 92
  • 119

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

As bothThe manual says the following about arithmetic expansion and:

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.

And command substitutions can be nested, the shell expands them in the proper nesting ordersubstitution is described as

... executing command in a subshell environment

which means all expansions take place.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

As both arithmetic expansion and command substitutions can be nested, the shell expands them in the proper nesting order.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

The manual says the following about arithmetic expansion:

All tokens in the expression undergo parameter and variable expansion, command substitution, and quote removal.

And command substitution is described as

... executing command in a subshell environment

which means all expansions take place.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6 
Source Link
choroba
  • 49.6k
  • 7
  • 92
  • 119

Your book is not exactly correct. See man bash for the exact order:

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 pathname expansion.

Note the usage of commas and semicolons. The parameter, variable, and arithmetic expansions plus the command substitution all happen with the same order.

As both arithmetic expansion and command substitutions can be nested, the shell expands them in the proper nesting order.

$ echo $((1 + $(echo $((2+$(printf %s 3)))))) 6