Lectures 15 - 19 Flashcards
What is a regular expression?
A way of defining patterns to be matched or searched for in text
In a regular expression, what do normal characters match?
They match themselves
In a regular expression, what does a dot ( . ) match?
Any one character i.e anything at all
In a regular expression, what does a range of characters in square brackets match ( [abc], [a-f], [2-6])?
Any one character in the square brackets
In a regular expression, what do square brackets with a ^ at the start match?
Any character that is not in the square brackets
In a regular expression, what does a star (*) after a character denote?
Zero or more of the preceding character
So, cats* could match cat or cats or catss …
In a regular expression, what does a ^ outside of square brackets match?
The start of a line.
So, ^Now would match any line starting with Now
In a regular expression, what does a $ match?
The end of a line.
So, exit$ would match any ‘exit’ at the end of a line
How do we launch a bash file?
By using ‘bash ‘
How else can we run a bash file?
By making it executable:
- ’#!/bin/bash ‘ at start of file
- chmod a+x to make it executable
- ./ to invoke the file
Are shell variables global or local?
They are local to the process that defines them
How are shell variables defined?
= with no spaces in between
How can we get user input to be a variable’s value?
by using the read command
How can we use variables in the command line?
By using a $ before the variable name
How do we end an if statement in bash?
By using fi. this comes after the else condition