Bourne-Again Shell Flashcards
Unix shell provides ___
an interface that lets the user interact with the operating system by running commands
To bash, there are three kinds of tokens:
- reserved words
- words
- operators
reserved words
words that have meaning to the shell and its programming language; e.g. if and while
operators
composed of one or more metacharacters
metacharacters
characters that have special meaning to the shell on their own, e.g. | and >
words
sequences of characters separated by metacharacters, which include simple separators like spaces and tabs, or characters that are special to the shell language, like semicolons and ampersands
word beginning with a dollar sign introduces ___
a variable or parameter reference
all variables are ___ by default
global
redirections allow the user to ___
control the input to and output from invoked commands
pipeline
a linear list of commands in which the output of one command in the list becomes the input of the next
Bash reads from ___ when interactive, and ___ specified as an argument otherwise
the terminal
the script file
Bash uses the ___ to implement command line editing.
readline library
Readline is structured as a ___.
read/dispatch/execute/redisplay loop
To update the terminal display, readline must track three things:
- the current contents of the buffer of characters displayed on the screen
- the updated contents of that display buffer
- the actual characters displayed
In the presence of multibyte characters, ___, and the redisplay engine must take that into account.
the characters displayed do not exactly match the buffer
Readline’s approach to the string-to-string correction problem is ___
- identify the beginning and end of the portion of the buffer that differs
- compute the cost of updating just that portion, including moving the cursor backward and forward
- perform the lowest-cost update
- clean up by removing any characters remaining at the end of the line if necessary and position the cursor in the correct spot
Most modifications to the redisplay engine have been to ___ and ___.
- have non-displaying characters in the prompt (such as to change colours)
- cope with characters that take up more than a single byte
When the shell is not using readline, it uses either ___ or ___ to obtain input.
stdio
its own buffered input routines
The shell must ___ when reading from non-seekable devices such as pipes, but ___ when reading from files.
read scripts a character at a time
may buffer as many characters as it likes
When in a locale that supports multibyte characters, the shell ___.
stores its input in a buffer of bytes but treats these bytes as potentially multibyte characters
The initial job of the parsing engine is lexical analysis:
to separate the stream of characters into words and apply meaning to the result
basic unit upon which the parser operates is a ___
word
The lexical analyzer steps:
- takes lines of input from readline or another source
- breaks them into tokens at metacharacters
- identifies the tokens based on context
- passes them on to the parser to be assembled into statements and commands
Aliasing is implemented in the lexical phase, though the parser has to ___
inform the analyzer when expansion is permitted
Three types of quoting
backslash
single quote
double quote
backslash
escapes the next character
single quotes
prevents interpretation of all enclosed characters
double quotes
prevents some interpretation but allows word expansions, and treats backslashes differently
interface between parser and lexical analyzer:
parser encodes a certain amount of state and shares it with the analyzer to allow the sort of context-dependent analysis the grammar requires
After parsing, but before execution, many words are subject to ___
word expansion
types of variable expansion
- expansion of variable string values into new words and word lists
- act on the variable’s value itself
- some can depend on the state of the variable, e.g. set or not set
order of expansions
- brace expansion
- command substitution
- tilde expansion
- arithmetic expansion
The results of the word expansions are ___
split using the characters in the value of the shell variable IFS as delimiters
After the results are split, the shell interprets each word as a potential pattern and ___
tries to match it against an existing filename, including any leading directory path
During the command execution phase, ___
the set of expanded words is decomposed into a command name and set of arguments, and passed to the operating system as a file to be read and executed with the remaining words passed as the rest of the elements of argv
The input to the command execution phase is
the command structure built by the parser and a set of possibly-expanded words
builtin commands are executed by the shell without ___
creating a new process
When the shell executes jobs in the foreground, ___
it waits for the command to finish and collects its exit status
When the shell executes jobs in the background, ___
it immediately reads the next command
job control
the ability to move processes between the foreground and background, and to suspend and resume their execution
compound commands
consist of lists of one or more simple commands and are introduced by a keyword such as if or while
Lessons learned:
- detailed change logs
- extensive regression testing from the beginning
- standards, including participation in standardization process
- internal standards
- good documentation
- use what other software libraries that you can
- engage the user community, but don’t take it personally :)”
Would have done differently:
- introduced formal bash compatibility levels earlier
- more frequent releases, using some kind of public repository
- would have written a parser by hand