Skip to main content
Add steps, quote substitution, fix terminology
Source Link
vonbrand
  • 18.6k
  • 2
  • 40
  • 63

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:

$(command)

or

`command`

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 date:

thedate="$(date)"

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which, its value is the result of the substitution (that we could get after execution).
  4. We save that value in a variable, $thedate, for later use.
  5. We display the output value held by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 date:

thedate="$(date)"

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its value is the result of the substitution (that we could get after execution).
  4. We save that value in a variable, $thedate, for later use.
  5. We display the output value held by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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 the meaning of "command substitution" in shell-scripting in general, and in Bash in particular, as in:

$(command)

or

`command`

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 date:

thedate="$(date)"

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date), its value is the result of the substitution (that we could get after execution).
  4. We save that value in a variable, $thedate, for later use.
  5. We display the output value held by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 date:

thedate=$thedate="$(date)"

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its outputvalue is the result of the substitution (that we could get after execution).
  4. We save that value in a variable, $thedate, for later use.
  5. We display the output value holdheld by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 date:

thedate=$(date)

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its output is the result of the substitution (that we could get after execution).
  4. We display the output value hold by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 date:

thedate="$(date)"

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its value is the result of the substitution (that we could get after execution).
  4. We save that value in a variable, $thedate, for later use.
  5. We display the output value held by the variable with printf, per the command above.

Note: \n in printf is a line-break.

I think it's better.
Source Link

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:

$(command)

or

`command`

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 a singlean 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 date:

thedate=$(date)

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its output is the result of the substitution (that we could get after execution).
  4. We display the output value hold by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 a single 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 date:

thedate=$(date)

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its output is the result of the substitution (that we could get after execution).
  4. We display the output value hold by the variable with printf, per the command above.

Note: \n in printf is a line-break.

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:

$(command)

or

`command`

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 date:

thedate=$(date)

We can then print the result using the command printf:

printf 'The date is %s\n' "$thedate"
  1. The command substitution syntax is $().
  2. The command itself is date.
  3. Combining both we get $(date) which its output is the result of the substitution (that we could get after execution).
  4. We display the output value hold by the variable with printf, per the command above.

Note: \n in printf is a line-break.

I actually meant to fix an important typo (a redundant backtick), but I had to add some more stuff to the edit so I clarified some data and added links to another session and Wikipedia.
Source Link
Loading
Fix the printf explanation.
Source Link
Stephen Kitt
  • 481k
  • 59
  • 1.2k
  • 1.4k
Loading
I edit from my mobile device (took me some time compared to PC to clarify)....
Source Link
user88036
user88036
Loading
I edit from my mobile device (took me some time compared to PC to clarify)....
Source Link
Loading
added 5 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 11 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 11 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 11 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 11 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
deleted 9 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 8 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
added 685 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
Post Closed as "Duplicate" by bahamat, Romeo Ninov, Jeff Schaller, Satō Katsura, Anthony Geoghegan
deleted 115 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
Notice removed Reward existing answer by Arcticooling
Bounty Ended with Kusalananda's answer chosen by Arcticooling
Tweeted twitter.com/StackUnix/status/990037971821826053
Notice added Reward existing answer by Arcticooling
Bounty Started worth 50 reputation by Arcticooling
added 2 characters in body
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718
Loading
deleted 1702 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading
deleted 1702 characters in body
Source Link
Arcticooling
  • 4.5k
  • 17
  • 55
  • 107
Loading