The Bash Parser

It is imperative that you have a good understanding of how Bash reads your commands in and parses them into executable code. Knowing how Bash works with your code is the key to writing code that works well with Bash.

Note: Chet Ramey's chapter from The Architecture of Open Source Applications also describes the Bash parser in detail.

The following steps are executed for each command that resulted from splitting up the line of data:

After these steps, the next command, or next line is processed. Once the end of the file is reached (end of the script or the interactive bash session is closed) bash stops and returns the exit code of the last command it has executed.

Graphical Example

For a more simplified example of the process, see: http://stuff.lhunath.com/parser.png

Common Mistakes

These steps might seem like common sense after looking at them closely, but they can often seem counter-intuitive for certain specific cases. As an example, let me enumerate a few cases where people have often made mistakes against the way they think bash will interpret their command:


CategoryShell

BashParser (last edited 2017-10-10 14:25:02 by vrsimsbury)