Bash Command Substitution: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:


=Overview=
=Overview=
Command substitution is invoked with:
<syntaxhighlight lang="bash">
$(command)
</syntaxhighlight>
An equivalent, older and obsolete style is:
<syntaxhighlight lang="bash">
`command`
</syntaxhighlight>


Command substitution allows us to take the stdout output of a command or [[Bash_Functions#Returning_Values|function]], which would normally be sent to stdout of the executing shell, and save it as the value of a variable. To do this we place the command or the function within brackets, preceded by a $ sign.
Command substitution allows us to take the stdout output of a command or [[Bash_Functions#Returning_Values|function]], which would normally be sent to stdout of the executing shell, and save it as the value of a variable. To do this we place the command or the function within brackets, preceded by a $ sign.

Revision as of 18:41, 3 October 2019

Internal

Overview

Command substitution is invoked with:

$(command)

An equivalent, older and obsolete style is:

`command`


Command substitution allows us to take the stdout output of a command or function, which would normally be sent to stdout of the executing shell, and save it as the value of a variable. To do this we place the command or the function within brackets, preceded by a $ sign.

local content
content=$(ps -ef)