Bourne-Again Shell Flashcards

1
Q

Unix shell provides ___

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

To bash, there are three kinds of tokens:

A
  1. reserved words
  2. words
  3. operators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

reserved words

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

operators

A

composed of one or more metacharacters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

metacharacters

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

words

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

word beginning with a dollar sign introduces ___

A

a variable or parameter reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

all variables are ___ by default

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

redirections allow the user to ___

A

control the input to and output from invoked commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

pipeline

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

the terminal

the script file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Bash uses the ___ to implement command line editing.

A

readline library

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Readline is structured as a ___.

A

read/dispatch/execute/redisplay loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A
  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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

the characters displayed do not exactly match the buffer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A
  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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

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

A
  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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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

A

stdio

its own buffered input routines

19
Q

The shell must ___ when reading from non-seekable devices such as pipes, but ___ when reading from files.

A

read scripts a character at a time

may buffer as many characters as it likes

20
Q

When in a locale that supports multibyte characters, the shell ___.

A

stores its input in a buffer of bytes but treats these bytes as potentially multibyte characters

21
Q

The initial job of the parsing engine is lexical analysis:

A

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

22
Q

basic unit upon which the parser operates is a ___

23
Q

The lexical analyzer steps:

A
  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
Q

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

A

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