Bourne-Again Shell Flashcards Preview

The Architecture of Open Source Applications: Elegance, Evolution, and a Few Fearless Hacks > Bourne-Again Shell > Flashcards

Flashcards in Bourne-Again Shell Deck (43):
1

Unix shell provides ___

an interface that lets the user interact with the operating system by running commands

2

To bash, there are three kinds of tokens:

1. reserved words
2. words
3. operators

3

reserved words

words that have meaning to the shell and its programming language; e.g. if and while

4

operators

composed of one or more metacharacters

5

metacharacters

characters that have special meaning to the shell on their own, e.g. | and >

6

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

7

word beginning with a dollar sign introduces ___

a variable or parameter reference

8

all variables are ___ by default

global

9

redirections allow the user to ___

control the input to and output from invoked commands

10

pipeline

a linear list of commands in which the output of one command in the list becomes the input of the next

11

Bash reads from ___ when interactive, and ___ specified as an argument otherwise

the terminal
the script file

12

Bash uses the ___ to implement command line editing.

readline library

13

Readline is structured as a ___.

read/dispatch/execute/redisplay loop

14

To update the terminal display, readline must track three things:

1. the current contents of the buffer of characters displayed on the screen
2. the updated contents of that display buffer
3. the actual characters displayed

15

In the presence of multibyte characters, ___, and the redisplay engine must take that into account.

the characters displayed do not exactly match the buffer

16

Readline’s approach to the string-to-string correction problem is ___

1. identify the beginning and end of the portion of the buffer that differs
2. compute the cost of updating just that portion, including moving the cursor backward and forward
3. perform the lowest-cost update
4. clean up by removing any characters remaining at the end of the line if necessary and position the cursor in the correct spot

17

Most modifications to the redisplay engine have been to ___ and ___.

1. have non-displaying characters in the prompt (such as to change colours)
2. cope with characters that take up more than a single byte

18

When the shell is not using readline, it uses either ___ or ___ to obtain input.

stdio
its own buffered input routines

19

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

20

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

21

The initial job of the parsing engine is lexical analysis:

to separate the stream of characters into words and apply meaning to the result

22

basic unit upon which the parser operates is a ___

word

23

The lexical analyzer steps:

1. takes lines of input from readline or another source
2. breaks them into tokens at metacharacters
3. identifies the tokens based on context
4. passes them on to the parser to be assembled into statements and commands

24

Aliasing is implemented in the lexical phase, though the parser has to ___

inform the analyzer when expansion is permitted

25

Three types of quoting

backslash
single quote
double quote

26

backslash

escapes the next character

27

single quotes

prevents interpretation of all enclosed characters

28

double quotes

prevents some interpretation but allows word expansions, and treats backslashes differently

29

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

30

After parsing, but before execution, many words are subject to ___

word expansion

31

types of variable expansion

1. expansion of variable string values into new words and word lists
2. act on the variable’s value itself
3. some can depend on the state of the variable, e.g. set or not set

32

order of expansions

1. brace expansion
2. command substitution
3. tilde expansion
4. arithmetic expansion

33

The results of the word expansions are ___

split using the characters in the value of the shell variable IFS as delimiters

34

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

35

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

36

The input to the command execution phase is

the command structure built by the parser and a set of possibly-expanded words

37

builtin commands are executed by the shell without ___

creating a new process

38

When the shell executes jobs in the foreground, ___

it waits for the command to finish and collects its exit status

39

When the shell executes jobs in the background, ___

it immediately reads the next command

40

job control

the ability to move processes between the foreground and background, and to suspend and resume their execution

41

compound commands

consist of lists of one or more simple commands and are introduced by a keyword such as if or while

42

Lessons learned:

1. detailed change logs
2. extensive regression testing from the beginning
3. standards, including participation in standardization process
4. internal standards
5. good documentation
6. use what other software libraries that you can
7. engage the user community, but don’t take it personally :)"

43

Would have done differently:

1. introduced formal bash compatibility levels earlier
2. more frequent releases, using some kind of public repository
3. would have written a parser by hand