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 ___

A

word

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
Q

Three types of quoting

A

backslash
single quote
double quote

26
Q

backslash

A

escapes the next character

27
Q

single quotes

A

prevents interpretation of all enclosed characters

28
Q

double quotes

A

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

29
Q

interface between parser and lexical analyzer:

A

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
Q

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

A

word expansion

31
Q

types of variable expansion

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

order of expansions

A
  1. brace expansion
  2. command substitution
  3. tilde expansion
  4. arithmetic expansion
33
Q

The results of the word expansions are ___

A

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

34
Q

After the results are split, the shell interprets each word as a potential pattern and ___

A

tries to match it against an existing filename, including any leading directory path

35
Q

During the command execution phase, ___

A

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
Q

The input to the command execution phase is

A

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

37
Q

builtin commands are executed by the shell without ___

A

creating a new process

38
Q

When the shell executes jobs in the foreground, ___

A

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

39
Q

When the shell executes jobs in the background, ___

A

it immediately reads the next command

40
Q

job control

A

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

41
Q

compound commands

A

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

42
Q

Lessons learned:

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

Would have done differently:

A
  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