Lectures 15 - 19 Flashcards

1
Q

What is a regular expression?

A

A way of defining patterns to be matched or searched for in text

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

In a regular expression, what do normal characters match?

A

They match themselves

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

In a regular expression, what does a dot ( . ) match?

A

Any one character i.e anything at all

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

In a regular expression, what does a range of characters in square brackets match ( [abc], [a-f], [2-6])?

A

Any one character in the square brackets

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

In a regular expression, what do square brackets with a ^ at the start match?

A

Any character that is not in the square brackets

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

In a regular expression, what does a star (*) after a character denote?

A

Zero or more of the preceding character

So, cats* could match cat or cats or catss …

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

In a regular expression, what does a ^ outside of square brackets match?

A

The start of a line.

So, ^Now would match any line starting with Now

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

In a regular expression, what does a $ match?

A

The end of a line.

So, exit$ would match any ‘exit’ at the end of a line

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

How do we launch a bash file?

A

By using ‘bash ‘

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

How else can we run a bash file?

A

By making it executable:

  • ’#!/bin/bash ‘ at start of file
  • chmod a+x to make it executable
  • ./ to invoke the file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Are shell variables global or local?

A

They are local to the process that defines them

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

How are shell variables defined?

A

= with no spaces in between

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

How can we get user input to be a variable’s value?

A

by using the read command

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

How can we use variables in the command line?

A

By using a $ before the variable name

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

How do we end an if statement in bash?

A

By using fi. this comes after the else condition

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

What else is needed in a bash if statement?

A

It requires a ‘then’ keyword, like in Haskell.

17
Q

What do for loops need in bash?

A

For, do then done statements, like:
for thing in other thing
do

done

18
Q

Do while and until loops have the same syntax as for loops?

A

Yes - just change the keyword at the start