Useful things in Bash

What is $()

In a shell script or terminal command, the $() syntax is known as “command substitution.” It allows you to execute a command and use its output as part of another command or assigned to a variable. In the context of $(docker ps -q), it executes the docker ps -q command and captures its output (the container IDs of running containers in this case). Therefore we can combine shell commands.

For example, if docker ps -q returns two container IDs: 1234abcd and 5678efgh.
Using docker stop $(docker ps -q) is equivalent to running docker stop 1234abcd 5678efgh. The command substitution allows you to dynamically pass the output of one command as an argument to another command.


Андрей Писаревский

Author: Andrei Pisarevskii 

PHP | WordPress Team Lead. I have commercial programming experience since 2010 and expertise in the full cycle of web development: Frontend, Backend, QA, Server administration, managing large teams and Enterprise projects.

Leave a Reply

Your email address will not be published. Required fields are marked *