1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # GRAMMAR
- <command> ::= <token>+
- <pipe> ::= <command> '|' <pipe>
- | <command>
- <conj> ::= <pipe> '&&' <conj>
- | <pipe>
- <disj> ::= <conj> '||' <disj>
- | <conj>
- <line> ::= <disj> ('<' <token>)? ('>' <token>)? '&'?
- or in words:
- A command is a sequence of tokens like: grep -v foo
- A pipe is a sequence of commands with | between: ps aux | grep watch | grep -v grep
- A disj is a sequence of pipes with || in between, like: mount /proc || exit -1
- note: | binds tighter than && which binds tighter than ||
- And each line can optionally be set to run in the background/in parallel using &
- you can also (optionally) choose to redirect stdin/out
- # AST
- So the abstract syntax tree ends up being a right associative tree of '||' nodes,
- containing right associative trees of '&&' nodes, containing ... '|' nodes which
- contain command nodes.
- # VARIABLES
- After tokenization variables are expanded.
- The names of variables are made from these charactors: [A-Z0-9_]
- "Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit."
- * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
- The syntax is $VAR or ${VAR}. The reason we have ${VAR} is to allow things like ${FOO}BAR.
- # SYNTAX
- builtins
- 'cd' <directory>
|