> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bash Assign Default Value

The `:=` operator is a shell parameter expansion modifier used to assign a default value to a variable if that variable is currently unset or null (empty). Upon evaluation, it mutates the variable's state by assigning the evaluated fallback string and simultaneously substitutes that newly assigned value into the current expression.

```bash theme={"dark"}
${parameter:=word}
```

## Evaluation Mechanics

When the shell encounters `${parameter:=word}`, it evaluates the state of `parameter` based on the following logic:

1. **Unset:** If `parameter` has not been declared, `word` is expanded, assigned to `parameter`, and substituted.
2. **Null:** If `parameter` is declared but contains an empty string (`parameter=""`), `word` is expanded, assigned to `parameter`, and substituted.
3. **Set and Non-Null:** If `parameter` contains a value, `word` is ignored. No assignment occurs, and the existing value of `parameter` is substituted.

## Syntax Variations and Strictness

The presence or absence of the colon (`:`) dictates how the shell handles null values:

* **`${parameter:=word}` (With colon):** Triggers assignment if the variable is unset **or** null.
* **`${parameter=word}` (Without colon):** Triggers assignment **only** if the variable is unset. If the variable is null (an empty string), it retains the empty string, and `word` is ignored.

## Technical Constraints

* **Read-Only Parameters:** The `:=` operator cannot be used with positional parameters (e.g., `${1:=default}`) or special shell parameters (e.g., `${@:=default}`, `${?:=default}`). Attempting to do so results in a `bad substitution` or `cannot assign in this way` execution error, as these parameters are immutable.
* **Side Effects:** Because `:=` performs an in-place assignment, it is an expression with side effects. If the expansion is evaluated as a standalone command, the shell will attempt to execute the resulting string.

To evaluate the assignment purely for its side effect without executing the result, it is conventionally passed as an argument to the `:` (null) built-in utility:

```bash theme={"dark"}
: ${parameter:=word}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Bash Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
