I'm trying to understand how Bash parses command lines. I know spaces, pipes, and redirections affect how commands are split and connected, but I'd like to learn the complete set of parsing rules and the other syntax elements involved. What is the best reference for Bash's grammar, and what should I study first?
4 Answers
A useful way to learn the subject is to study material about parsing POSIX shell scripts and shell-script validation. That gives a broader view of how shell grammars work and how Bash-specific behavior differs from the POSIX rules.
For Bash’s actual grammar, the best reference is the `parse.y` file in the Bash source code. It uses a Bison-style grammar and shows how Bash recognizes commands, pipelines, lists, redirections, and other shell constructs.
There’s more involved than spaces, pipes, and redirections. Shell parsing also includes quoting, escaping, comments, operators, command substitutions, parameter expansion, arithmetic expansion, globbing, and control characters. It also helps to distinguish parsing from later steps such as expansions, word splitting, pathname expansion, and execution.
The Bash documentation is a good starting point, especially the reference material available through `info bash`. It explains the shell’s syntax and processing rules in a more approachable way than reading the parser source immediately.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically