Syntax

Bash Command Substitution Syntax

In Bash, command substitution: stores a command's output in a variable — today=$(date +%F)

Quick Answer

Syntax
today=$(date +%F)
BashSyntax

Command Substitution

Code example
today=$(date +%F)

Stores a command's output in a variable.

Learn More

How to command substitution in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash Command Substitution Syntax

Use today=$(date +%F).

Related Syntax References

Frequently asked questions

What is the Bash syntax for command substitution?

Use this pattern: today=$(date +%F)

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify