105.1 Lesson 2 Flashcards

1
Q

Where does a shell/local variable live?

A

In the shell in which they were created.

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

Where does an environment/global variable live?

A

In the shell where they were created and in children shells and/or processes.

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

Where do you configure variables, aliases and functions for a shell?

A

In startup files.

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

Accessing the value of a variable is called

A

variable referencing

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

How do you reference the variable distro?

A

$distro

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

Which characters may the name of a variable contain?

A

a-Z
A-Z
0-9
underscore _

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

What is wrong with the variable 1distro?

A

It starts with a number.

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

What is wrong with the variable “my distro”=zorinos?

A

It contains a space

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

The value of a variable is also called

A

reference

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

Which characters may the value of a variable contain?

A
a-z
A-Z
0-9
most other characters
$ ! * . / etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is wrong with the following variable value?

distro=zorin 12.4

A

It contains a space and is not enclosed in quotes.

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

When must a variable value be enclosed in quotes?

A
When it contains
<
>
or
| (pipe symbol)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Are single and double quotes always interchangeable?

A

no

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

What do the semantics of single and double quotes depend on?

A

If they are used for assigning or for referencing

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

How do single quotes interpret characters of a variable’s value in the context of variable assignment?

A

literally

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

How is $lizard interpreted during variable assignment when using double quotes?

A

The variable $lizard is substituted with its value.

17
Q

What happens to initial and extra spaces in a variables value during variable referencing when no double quotes are used?

A

The spaces get lost.

18
Q

How do you avoid field splitting and pathname expansion when referencing a variable?

A

echo “$lizard”

19
Q

Variables in bash are also called

A

shell parameters

20
Q

variable referencing is also called

A

shell parameter expansion

21
Q

How many expansions does shell parameter expansion consist of?

22
Q

Name one expansion that is carried out during shell parameter expansion?

A

word splitting

23
Q

What happens in the word splitting process of shell parameter expansion?

A

The result of the other expansions is split into words using the shell parameter $IFS.

24
Q

What is the default value of $IFS?

25
What happens to space tab and newline characters that do not delimit words during word splitting?
They are ommited.
26
What happens during filename expansion?
Bash scans each word for the characters * ? and [ . If a word is found the word is replaced with a list of filenames matching the pattern.
27
What does an exclamation mark that is not the last character in the string refer to in a variables value?
a history event
28
backslashes in variable values must be
escaped with another backslash
29
if a backslash is the last character in a variables value it is interpreted as a
newline
30
create an immutable variable
``` readonly reptile=tortoise #or reptile=tortoise readonly reptile ```
31
List all readonly variables in our current session
``` readonly #or readonly -p ```
32
output all the currently assigned shell variables and functions
set
33
spawn a child process in the current shell
bash
34
unset the variable reptile
unset reptile