TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-- (double dash) token is a POSIX-standard end-of-options indicator (or delimiter). When a command parser encounters --, it ceases option processing and treats all subsequent arguments strictly as literal operands, regardless of whether those arguments begin with a hyphen (-).
Parsing Mechanics
In Bash, argument parsing is typically handled by thegetopts builtin for shell scripts, or by external utilities utilizing C library functions like getopt() or getopt_long(). These parsers recognize -- as a hardcoded termination token defined by POSIX Utility Syntax Guideline 10.
When the parser reads the argument vector (argv):
- It evaluates arguments starting with
-as flags or options. - Upon encountering the exact string
--, the parser halts its scanning loop. - The parser increments its internal index (such as
OPTINDin Bash) past the--token. It does not automatically consume or discard the--token from the shell’s positional parameters. - All remaining elements in the argument vector are treated as non-option operands. For external commands, these are processed internally via their C
argvarray. For Bash builtins or shell scripts, they are processed as literal strings or assigned to the shell’s positional parameters (e.g.,$1,$2), depending on the specific command.
Interaction with set
While -- is a universal POSIX guideline implemented by most standard utilities (e.g., rm, grep, ls), it has a specific, notable behavior when used with the Bash set builtin. The set command uses -- to safely assign values to the shell’s positional parameters without them being interpreted as shell options.
Interaction with getopts
When writing custom Bash scripts, the -- delimiter directly affects the OPTIND (Option Index) variable used by the getopts builtin.
./script.sh -x foo -- -y bar:
getoptsparses-xand its argumentfoo.getoptsencounters--, stops parsing, and incrementsOPTINDpast the--token.- The
shiftcommand removes-x,foo, and--from the parameter list. - The string
-yis never evaluated as an option; it is retained as the literal string$1, andbarbecomes$2.
Master Bash with Deep Grasping Methodology!Learn More





