> ## 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 Exported Variable

An exported variable in Bash is a shell variable that has been marked for inclusion in the environment block of subsequently executed child processes. By default, standard shell variables are local to the current shell instance and are not inherited by external commands or independent scripts. Applying the export attribute to a variable promotes it to an environment variable, ensuring its identifier and value are passed to any process spawned from that shell via the `execve` system call.

## Syntax

Bash provides multiple ways to apply the export attribute to a variable:

```bash theme={"dark"}

# 1. Declaration and assignment in a single statement
export VAR_NAME="value"


# 2. Applying the export attribute to an existing shell variable
VAR_NAME="value"
export VAR_NAME


# 3. Using the declare builtin with the export (-x) flag
declare -x VAR_NAME="value"
```

## Process Mechanics and Scope

* **Unidirectional Inheritance:** When a child process is created (typically via `fork` and `exec`), it receives a deep copy of the parent's exported environment. Because it is a copy, any modifications made to the variable within the child process are strictly local to that child and do not propagate back to the parent shell.
* **Subshell Behavior:** Subshells (created using `( )`, command substitution `$()`, or background tasks `&`) inherit all variables from the parent shell's memory space, regardless of the export attribute, because they are created via `fork` without `exec`. External commands and scripts executed as separate processes, however, strictly require the export attribute to access the variable.
* **Per-Command Exporting:** Bash allows a variable to be exported temporarily to the environment of a single command without modifying the parent shell's environment state.

```bash theme={"dark"}

# VAR_NAME is placed in the environment block exclusively for 'command'
VAR_NAME="value" command arg1 arg2
```

## Attribute Management

The export attribute modifies the state of a variable, but it can be manipulated or removed independently of the variable's value.

```bash theme={"dark"}

# Print all variables in the current shell that possess the export attribute
export -p

# Alternatively:
declare -x


# Remove the export attribute (demotes it back to a local shell variable)
export -n VAR_NAME


# Destroy the variable entirely (removes it from both the shell and the environment)
unset VAR_NAME
```

## POSIX Compliance Note

While `export VAR="value"` is valid in Bash and POSIX-compliant shells, the `declare -x` syntax is a Bash-specific extension and will fail in strict POSIX environments (like `sh` or `dash`).

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