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.,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.
?, *, $) 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:
Positional Parameters
These parameters hold the arguments passed to a script, a shell function, or set via theset 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$10as$1followed by the string0.
Special Parameters
These parameters are denoted by specific symbols or the digit0. 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 theIFS(Internal Field Separator) variable. IfIFSis unset, parameters default to being separated by spaces. IfIFSis explicitly set to null/empty (IFS=""), the parameters are concatenated together without any intervening separators. Syntax visualization:"$1c$2c$3"(wherecis theIFScharacter). 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).
- Unquoted: Behaves identically to unquoted
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 between0and255.$$: 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.,-ifor interactive) or modified during execution via thesetbuilt-in command (e.g.,set -eorset -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





