Recall & Review
beginner
What does the
&& operator do in command chaining?It runs the second command only if the first command succeeds (returns exit status 0). Think of it as "and then if successful."
Click to reveal answer
beginner
What happens when you use the
|| operator between two commands?The second command runs only if the first command fails (returns non-zero exit status). It's like saying "or else run this."
Click to reveal answer
beginner
How does the
; operator work in command chaining?It runs commands sequentially, one after another, regardless of whether the previous command succeeded or failed.
Click to reveal answer
intermediate
Example: What will happen with
mkdir test && cd test if the directory already exists?The
mkdir test will fail because the directory exists, so cd test will NOT run because of the && operator.Click to reveal answer
intermediate
Why might you use
command1 || command2 in a script?To try
command1 and if it fails, automatically run command2 as a fallback or error handler.Click to reveal answer
What does
cmd1 && cmd2 do?✗ Incorrect
&& runs the second command only if the first command succeeds.What happens with
cmd1 || cmd2?✗ Incorrect
|| runs the second command only if the first command fails.Which operator runs commands one after another no matter what?
✗ Incorrect
The semicolon
; runs commands sequentially regardless of success or failure.If you want to run
cmd2 only when cmd1 fails, which do you use?✗ Incorrect
|| runs the second command only if the first fails.What will
mkdir newdir; cd newdir do?✗ Incorrect
The semicolon runs commands one after another no matter what.
Explain how the
&&, ||, and ; operators differ in chaining commands.Think about success and failure conditions for each operator.
You got /3 concepts.
Describe a real-life situation where you would use
command1 || command2 in a script.Imagine trying something and doing something else if it doesn't work.
You got /3 concepts.