This question already has an answer here:
I'm using Ubuntu 16.04 with Bash and I tried to read in Wikipedia, in here and in here, but I failed to understand what is the meaning of "command substitution" in shell-scripting in general, and in Bash in particular, as in:
What is the meaning of this term?
Edit: When I first published this question I already knew the pure concept of substitution and also the Linux concept of variable substitution (replacing a variable with its value by execution), yet I still missed the purpose of this shell feature from the documentation for whatever reason or group of reasons.
My answer after question locked
Command substitution is an operation with dedicated syntax to both execute a command and to have this command's output hold (stored) by a variable for later use.
An example with
We can then print the result using the command
printf 'The date is %s\n' "$thedate"
- The command substitution syntax is
- The command itself is
- Combining both we get
$(date)which its output is the result of the substitution (that we could get after execution).
- We display the output value hold by the variable with
printf, per the command above.
printf is a line-break.