Syntax

Bash Default Value for a Variable Syntax

In Bash, default value for a variable: uses a default if the variable is unset or empty — ${name:-guest}

Quick Answer

Syntax
${name:-guest}
BashSyntax

Default Value for a Variable

Code example
${name:-guest}

Uses a default if the variable is unset or empty.

Learn More

How to default value for a variable in Bash

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

Bash Default Value for a Variable Syntax

Use ${name:-guest}.

Related Syntax References

Frequently asked questions

What is the Bash syntax for default value for a variable?

Use this pattern: ${name:-guest}

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