Command substitution in Bash scripting is a process that allows the output of a command to replace the command itself. It’s executed within parentheses, and can be used anywhere a regular string could be used. This feature enables us to store the output of a command into a variable or use it as an argument for another command. There are two forms: $(command) and command . The former is more modern and preferred due to its readability and ease of nesting.
For example:
date_today=$(date)
echo "Today's date is $date_today"
In this script, ‘date’ command is substituted by its output which is then stored in ‘date_today’ variable.