Search code examples
bashexpansioncommand-substitution

What is happening in this command substitution?


I have written the following command substitution and executed in in a bash shell:

$(echo echo 1; echo 2; echo 3) #output: 1 2 3

Why is the double echo required in the first expression, while only single echos are required in the second and third?


Solution

  • It has to do with what you've actually asked the shell to do. That is as follows:

    "Echo the result of echo 1; echo 2; echo 3"