Skip to main content

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 special parameters and positional parameters are internally defined, read-only entities maintained by the shell to store execution context, state information, and command-line arguments. In strict Bash semantics, a “variable” is a parameter denoted by a name (an identifier beginning with an alphabetic character or an underscore, followed by alphanumeric characters or underscores). Entities denoted by symbols (e.g., ?, *, $) or digits are technically classified as parameters, not variables. Their values are automatically populated by the shell during script execution or command invocation and cannot be directly reassigned using standard assignment operators. They are accessed using standard parameter expansion syntax:
$1

# or
${?}

Positional Parameters

These parameters hold the arguments passed to a script, a shell function, or set via the set built-in command. Positional parameters are strictly denoted by digits greater than zero, are counted by $#, and are affected by the shift command.
  • $1$9: Expands to the specific positional parameter corresponding to the integer.
  • ${10}${N}: Expands to positional parameters beyond the ninth. Parameter expansion syntax using curly braces is strictly required for double-digit integers to prevent the shell from interpreting $10 as $1 followed by the string 0.

Special Parameters

These parameters are denoted by specific symbols or the digit 0. They provide metadata about the shell’s state, process execution, or aggregate the positional parameters.

Argument Aggregators

These parameters provide metadata about the positional parameters or group them into single expansions.
  • $#: Expands to the decimal integer representing the total number of positional parameters passed. It does not count $0.
  • $*: Expands to all positional parameters.
    • Unquoted: Expands to separate words subject to word splitting and pathname expansion (globbing).
    • Double-quoted ("$*"): Expands to a single string containing all parameters separated by the first character of the IFS (Internal Field Separator) variable. If IFS is unset, parameters default to being separated by spaces. If IFS is explicitly set to null/empty (IFS=""), the parameters are concatenated together without any intervening separators. Syntax visualization: "$1c$2c$3" (where c is the IFS character). When there are zero positional parameters passed, "$*" expands to a single empty string (one empty word).
  • $@: Expands to all positional parameters.
    • Unquoted: Behaves identically to unquoted $* (subject to word splitting and pathname expansion).
    • Double-quoted ("$@"): Expands each parameter into a discrete, separate word. Syntax visualization: "$1" "$2" "$3". When there are zero positional parameters passed, "$@" expands to nothing (zero words).

Process and Execution State

These parameters track the lifecycle, identification, and exit status of processes managed by the shell.
  • $0: Expands to the name of the shell or shell script being executed. It is a special parameter, not a positional parameter.
  • $?: Expands to the exit status (return code) of the most recently executed foreground pipeline. It evaluates to an integer between 0 and 255.
  • $$: Expands to the Process ID (PID) of the current shell process. In a subshell environment, it expands to the PID of the invoking parent shell, not the subshell itself.
  • $!: Expands to the Process ID (PID) of the most recently executed asynchronous (background) command.

Shell Environment State

These parameters expose internal shell configurations and historical command data.
  • $-: Expands to a string consisting of the current set of shell option flags. This includes flags specified upon invocation (e.g., -i for interactive) or modified during execution via the set built-in command (e.g., set -e or set -x).
  • $_: Expands to the absolute file name of the shell or script being executed as passed in the environment or argument list. After initial execution, it dynamically updates to expand to the final argument of the previous simple command executed in the foreground.
Master Bash with Deep Grasping Methodology!Learn More