Bash – $() in a command

bashcommandshell

What is $() in Linux Shell Commands?

For example:

chmod 777 $(pwd)

Best Answer

It's very similar to the backticks ``.

It's called command substitution (posix specification) and it invokes a subshell. The command in the braces of $() or beween the backticks (``) is executed in a subshell and the output is then placed in the original command.

Unlike the backticks, the $(...) form can be nested. So you can use command substitution inside another substitution.

There are aso differences in escaping characters within the substitution. I prefer the $(...) form.

Related Question