1/31
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What must you understand to develop a script in a particular language?
The syntax of the language.
What is the difference between a syntax error and a logical error?
Syntax error prevents the script from running; logical error could cause it to operate differently from what was intended.
Why add comments in code (best practice)?
Assist with maintaining it.
How is a comment line treated by the compiler or interpreter?
Ignored.
What indicates a comment line in Bash (and several other languages)?
Hash or pound sign (#).
What is a variable in a script?
A label for some value that can change as the script executes.
How are variables usually set up at the start of the routine where they’re used?
Declared, defined as a particular data type, and given an initial value.
What is an argument/parameter in a script?
A variable that is passed to the script when it is executed.
How does Bash refer to arguments by position?
$1, $2, and so on.
What is a constant in a script?
A label for a value that remains constant throughout the execution of the script.
In normal execution, how are statements processed in a script?
In turn from top to bottom.
What are the two main types of conditional execution?
Branches and loops.
What is a branch?
An instruction to execute a different sequence of instructions based on the outcome of some logical test.
In the Bash if example, what does -z test?
Whether the first positional parameter ($1) is unset or empty.
Why enclose the variable in double quotes in the condition?
Safer way to treat the input from the user (supplied as the argument).
Why use double quotes in echo "Hello $1" instead of single quotes?
Allows the variable to expand to whatever it represents.
What is a loop?
Allows a statement block to be repeated based on some type of condition.
When is a For loop used?
When the number of iterations is predictable.
What do While/Until loops do?
Repeat an indeterminate number of times until a logical condition is met.
In the Until ping example, what does &/dev/null do?
Stops the usual ping output from being written to the terminal by redirecting it to a null device.
What should you ensure about loops in your code?
No unintended or infinite loops.
What does a logical test resolve to?
TRUE or FALSE.
What does == (or -eq) mean?
Is equal to (returns TRUE if both conditions are the same).
What does != (or -ne) mean?
Is not equal to (returns FALSE if both conditions are the same).
What do && and || mean in logical tests?
&& AND: if both conditions are TRUE, whole statement TRUE; || OR: if either condition is TRUE, whole statement TRUE.
What does a loop do in a script?
Repeats a section of the script based on some type of circumstance.
What kind of loop runs for a specific number of times?
For loop.
What kind of loop runs for an unknown number of times until a logical condition is not true anymore?
Until loop.
What kind of loop runs for an unknown number of times, but only while a logical condition is true?
While loop.
In the washing dishes example, what does a for loop look like?
Wash 5 plates and then stop.
In the washing dishes example, what does an until loop look like?
Washing dishes until all the plates are done; once there are no plates and you're left with just pots and pans, move on.
In the washing dishes example, what does a while loop look like?
Washing as long as there are dishes on the countertop; as soon as there are no dishes on that counter, you're done.