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

The `*` (asterisk) token in Bash is a context-dependent, overloaded operator whose evaluation behavior is strictly determined by the shell's parsing phase, the syntactic construct enclosing it, and the presence of quoting mechanisms.

**Quoting and Escaping**
The special parsing properties of the `*` token in pathname expansion, string pattern matching, and regular expressions are entirely neutralized when quoted or escaped. Enclosing the asterisk in single quotes (`'*'`), double quotes (`"*"`), or escaping it with an unquoted backslash (`\*`) forces the shell to evaluate it as a literal asterisk character rather than a quantifier or wildcard. Because `*` has no special meaning inside double quotes, a backslash preceding it (`"\*"`) is not stripped and evaluates to a literal backslash followed by an asterisk.

```bash theme={"dark"}
echo "*"
echo '*'
echo \*
[[ $string == "*" ]]
```

**Pathname Expansion**
During the pathname expansion phase, an unquoted `*` functions as a wildcard character matching any string of zero or more characters. By default, it does not match a leading period (`.`) or a directory separator (`/`). Its parsing behavior is mutable via shell options (`shopt`), specifically `dotglob` (allows matching hidden files) and `nocaseglob` (disables case sensitivity).

If the `*` wildcard matches no files, Bash's default behavior is to leave the pattern unexpanded, evaluating it as the literal string containing the asterisk (e.g., `*.txt` remains `*.txt`). This behavior can be modified using the `nullglob` shell option, which causes unmatched patterns to expand to a null string, or the `failglob` shell option, which triggers an expansion error upon encountering an unmatched pattern.

When the `globstar` option is enabled (`shopt -s globstar`), a double asterisk (`**`) evaluates to a recursive directory traversal, but *only* when it is a standalone path component. If `**` is adjacent to other characters within the same path component (e.g., `prefix**`), it degrades and functions as a standard single `*`.

```bash theme={"dark"}
echo prefix*suffix
echo dir/**/*.txt
```

**String Pattern Matching**
Outside of filesystem interaction, an unquoted `*` functions as a standard globbing wildcard for string pattern matching within specific syntactic constructs. When evaluated on the right-hand side of the `==` or `!=` operators within the `[[ ]]` conditional command, or within the pattern clauses of a `case` statement, an unquoted `*` matches zero or more characters of the target string. If the `*` is quoted, it loses its globbing properties and matches a literal asterisk.

```bash theme={"dark"}
[[ $string == *pattern* ]]
[[ $string != prefix*"literal_asterisk_here*" ]]

case $string in
    *pattern*) echo "Match found" ;;
esac
```

**Arithmetic Multiplication and Exponentiation**
Within arithmetic evaluation contexts (`$(( ))`, `(( ))`, `let`), the asterisk functions as a mathematical operator for integer arithmetic. A single asterisk (`*`) operates as a binary multiplication operator. A double asterisk (`**`) operates as an exponentiation operator, evaluating the left operand to the power of the right operand.

```bash theme={"dark"}
result=$(( operand1 * operand2 ))
result=$(( base ** exponent ))
(( variable = operand1 * operand2 ))
```

**Special Parameters and Array Subscripts**
When utilized as a Special Parameter (`$*`) or an array subscript (`[*]`), the operator expands to all positional parameters or all initialized elements of an array, respectively. The evaluation mechanics change fundamentally based on double-quoting:

* **Unquoted** (`$*` or `${array[*]}`): Expands to separate words, immediately subjecting the output to word splitting and pathname expansion.
* **Quoted** (`"$*"` or `"${array[*]}"`): Expands to a single contiguous string, concatenating each element separated by the first character of the Internal Field Separator (`$IFS`) variable.

```bash theme={"dark"}
echo $*
echo "$*"
echo "${array_name[*]}"
```

**Variable Name Expansion**
Within parameter expansion, using the `!` prefix followed by a string and the `*` operator expands to the names of all currently defined variables that begin with the specified prefix.

```bash theme={"dark"}
echo "${!prefix*}"
```

**Parameter Expansion (Substring Processing)**
Within brace-enclosed parameter expansion, `*` acts as a globbing wildcard to define patterns for substring removal or replacement. It matches zero or more characters to identify the exact prefix or suffix boundary to be stripped or substituted.

```bash theme={"dark"}
echo "${variable#*pattern}"  # Non-greedy prefix removal
echo "${variable##*pattern}" # Greedy prefix removal
echo "${variable%pattern*}"  # Non-greedy suffix removal
echo "${variable%%pattern*}" # Greedy suffix removal
echo "${variable/pattern*/replacement}" # Pattern replacement
```

**Extended Globbing**
When the `extglob` shell option is enabled (`shopt -s extglob`), `*` acts as a pattern quantifier. The syntactic construct `*(pattern-list)` matches zero or more occurrences of the provided patterns, where multiple patterns are separated by a pipe (`|`). Because `extglob` alters the shell's parsing phase, the option must be explicitly enabled before the construct is parsed to avoid syntax errors.

```bash theme={"dark"}
shopt -s extglob
echo *(pattern1|pattern2)
```

**Extended Regular Expressions (ERE)**
When evaluated on the right-hand side of the `=~` binary operator within the `[[ ]]` conditional construct, `*` ceases to be a globbing wildcard. Instead, it functions as a POSIX Extended Regular Expression quantifier, dictating that the preceding character, character class, or subexpression must occur zero or more times. The right-hand side must remain unquoted for `*` to function as a regex quantifier; if quoted, Bash treats it as a literal asterisk character.

```bash theme={"dark"}
[[ $string =~ preceding_element* ]]
```

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