> ## 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 Unary Minus

The `-` (hyphen or minus) character in Bash is a heavily overloaded lexical token. Its behavior is strictly determined by its syntactic context, functioning variously as an arithmetic operator, a parameter expansion modifier, a special parameter, a file descriptor closure token, a pattern matching range indicator, a conditional test prefix, or a directory navigation shortcut.

## Arithmetic Operators

Within an arithmetic evaluation context (`$(( ))`, `(( ))`, `let`, or variables typed with `declare -i`), `-` functions as a binary subtraction operator, a unary negation operator, and forms the unary pre-decrement and post-decrement operators (`--`).

```bash theme={"dark"}

# Binary subtraction
(( result = operand1 - operand2 ))


# Unary negation
(( result = -operand ))


# Pre-decrement and post-decrement
(( --operand ))
(( operand-- ))
```

## File Descriptor Closure

In redirection operations, appending `-` to the file descriptor duplication operators (`>&` or `<&`) instructs the shell to close the specified file descriptor rather than duplicating it.

```bash theme={"dark"}

# Close standard output (fd 1)
>&-


# Close standard input (fd 0)
<&-


# Close a specific file descriptor (e.g., fd 3)
3>&-
```

## Special Parameter (Shell Options)

The hyphen acts as a core special parameter (`$-`). When expanded, it yields a string containing the current set of single-letter shell option flags enabled in the current Bash environment (e.g., `himBH`).

```bash theme={"dark"}

# Expands to current shell options
echo $-
```

## Parameter Expansion (Default Value Substitution)

In brace parameter expansion, `-` acts as a fallback operator. It instructs the shell to evaluate to a specified default string if the target parameter is unset. When combined with a colon (`:-`), it triggers the fallback if the parameter is either unset or null (empty).

```bash theme={"dark"}

# Substitutes 'default_value' only if 'var' is strictly unset
${var-default_value}


# Substitutes 'default_value' if 'var' is unset OR null
${var:-default_value}
```

## Pattern Matching Range Operator

Within bracket expressions `[ ]` used in pathname expansion (globbing) and regular expression matching (`[[ =~ ]]`), `-` defines a contiguous character range based on the current locale's collating sequence.

```bash theme={"dark"}

# Globbing character range
ls *[a-z]*


# Regular expression character range
[[ $string =~ [0-9] ]]
```

## Conditional Test Prefix

Within the `test` builtin, POSIX brackets `[ ]`, and Bash extended test keywords `[[ ]]`, `-` is the required prefix for unary file/string operators and binary algebraic comparison operators.

```bash theme={"dark"}

# Unary operator prefix (e.g., -z for zero-length string, -f for regular file)
[[ -z $variable ]]


# Binary operator prefix (e.g., -eq for arithmetic equality)
[[ $val1 -eq $val2 ]]
```

## Here-Document Tab Stripping

When appended to the here-document redirection operator (`<<`), forming `<<-`, the hyphen modifies the parsing of the here-document. It instructs the shell to strip all leading tab characters (but not spaces) from the subsequent lines of the document body and the terminating delimiter.

```bash theme={"dark"}
command <<-DELIMITER
	text_with_leading_tabs
DELIMITER
```

## Previous Working Directory Alias

When passed as the sole argument to the `cd` builtin, `-` is parsed as a reserved alias for the `$OLDPWD` environment variable. It instructs the shell to change the current working directory to the previous working directory and prints the new path to standard output.

```bash theme={"dark"}
cd -
```

## Option Prefix and End-of-Options Marker

The `-` character is the standard prefix for short (single-character) options passed to Bash builtins and external commands. Furthermore, a standalone double hyphen (`--`) is parsed as the end-of-options indicator, forcing all subsequent arguments to be treated as positional parameters (operands), even if they begin with a `-`.

```bash theme={"dark"}

# Short option prefix
command -x -y


# End-of-options marker
command -- -filename_starting_with_hyphen
```

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