Command Substitution

noun

say it: “kuh-MAND sub-stih-TOO-shun” /kəˈmænd ˌsʌbstɪˈtuʃən/

A way of running a command inside another one, so that the first command's output is used as a value.

What is command substitution?

Command substitution, $(command), read "the output of", runs a command and puts what it printed in its place. It keeps a command's answer in a variable or builds it into a name, such as a backup named after today's date. Keep it inside double quotes.

today=$(date +%F)
tar -czf "cards-$today.tar.gz" cards    # cards-2026-11-09.tar.gz

In a sentence

  • “today=$(date +%F) uses command substitution to keep the date in a variable.”
  • “With command substitution, the backup's name has today's date in it.”

Level: Apprentice · More Unix terms at this level

Updated