> ## 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 Integer Attribute

The integer attribute in Bash is a variable property that forces the shell to treat the variable's value strictly as an integer. When this attribute is set, any subsequent assignment to the variable undergoes automatic arithmetic expansion, evaluating mathematical expressions and resolving variable references without requiring explicit arithmetic syntax (like `$((...))` or `let`).

## Declaration Syntax

The integer attribute is applied using the `declare`, `local`, or `typeset` builtins with the `-i` option.

```bash theme={"dark"}
declare -i variable_name
local -i variable_name    # Used for local scope within functions
typeset -i variable_name  # Legacy equivalent to declare
```

## Assignment Behavior and Evaluation Rules

Once a variable possesses the integer attribute, the Bash parser alters how it processes the right-hand side of an assignment to that variable.

1. **Automatic Arithmetic Evaluation:** Strings containing valid arithmetic operators are evaluated mathematically before assignment.
2. **Implicit Variable Dereferencing:** Strings that are not recognized as integers or operators are treated as variable names. Bash attempts to dereference them automatically without requiring the `$` prefix.
3. **Recursive Resolution and Fallback:** Bash arithmetic evaluation is recursive. If a variable resolves to a non-numeric string, Bash treats that resulting string as another variable name and continues to dereference it. The evaluation only resolves to `0` if the final variable in the resolution chain is unset or null.
4. **Arithmetic Addition via `+=`:** When the integer attribute is set, the `+=` assignment operator performs mathematical addition instead of standard string concatenation.
5. **Floating-Point Rejection:** Because Bash's arithmetic evaluator only supports integers, attempting to assign a floating-point number results in a syntax error.

## Syntax Visualization

```bash theme={"dark"}

# Apply the integer attribute
declare -i num


# 1. Automatic arithmetic evaluation
num="10 + 5"      
echo $num         # Output: 15


# 2. Implicit variable dereferencing
val=4
num="val * 3"     
echo $num         # Output: 12


# 3. Recursive resolution and fallback
a="b"
b="10"
num="a"           # 'a' resolves to 'b', 'b' resolves to 10
echo $num         # Output: 10

num="unset_var"   # Resolves to 0 because 'unset_var' is unset
echo $num         # Output: 0


# 4. Arithmetic addition via +=
num=10
num+=5            # Adds 5 mathematically, does not append "5"
echo $num         # Output: 15


# 5. Floating-point rejection
num="3.14"        # bash: 3.14: syntax error: invalid arithmetic operator
```

## Attribute Removal

The integer attribute is stripped from a variable using the `+i` flag. Once removed, the variable reverts to standard Bash string assignment behavior.

```bash theme={"dark"}
declare +i variable_name
```

```bash theme={"dark"}
declare -i num=10
declare +i num


# Reverts to literal string assignment
num="10 + 5"
echo $num         # Output: 10 + 5 


# Reverts to string concatenation
num+=5
echo $num         # Output: 10 + 55 
```

<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>
