Challenge - 5 Problems
Command Chaining Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
π» Command Output
intermediateWhat is the output of this chained command?
Consider the following command run in a Linux shell:
What will be printed?
echo Hello && echo World || echo FailWhat will be printed?
Linux CLI
echo Hello && echo World || echo Fail
Attempts:
2 left
π‘ Hint
Remember that && runs the next command only if the previous succeeds, and || runs the next command only if the previous fails.
β Incorrect
The first echo prints 'Hello' and succeeds, so the second echo runs and prints 'World'. Since the second command succeeds, the || part does not run.
π» Command Output
intermediateWhat happens with semicolon chaining?
What is the output of this command?
Note: 'false' is a command that always fails.
echo Start; false; echo EndNote: 'false' is a command that always fails.
Linux CLI
echo Start; false; echo End
Attempts:
2 left
π‘ Hint
Semicolon runs all commands regardless of success or failure.
β Incorrect
Semicolon separates commands to run one after another no matter what. So 'Start' prints, then 'false' runs (fails silently), then 'End' prints.
π» Command Output
advancedWhat is the output of this mixed chaining?
What will this command print?
false && echo No || echo Yes; echo DoneLinux CLI
false && echo No || echo Yes; echo Done
Attempts:
2 left
π‘ Hint
&& runs next only if previous succeeds; || runs next only if previous fails; semicolon always runs next.
β Incorrect
false fails, so 'echo No' after && does not run. The || runs 'echo Yes'. Then semicolon runs 'echo Done'.
π» Command Output
advancedWhat error or output occurs here?
What happens when running this command?
mkdir test_dir && cd test_dir || echo FailedLinux CLI
mkdir test_dir && cd test_dir || echo Failed
Attempts:
2 left
π‘ Hint
If mkdir succeeds and cd succeeds, || echo Failed does not run.
β Incorrect
If 'test_dir' does not exist, mkdir creates it and succeeds, cd changes directory successfully, so echo Failed does not run and no output appears.
π» Command Output
expertWhat is the output of this complex chain?
Analyze this command:
What will be printed?
echo Start && false || echo Middle && echo EndWhat will be printed?
Linux CLI
echo Start && false || echo Middle && echo End
Attempts:
2 left
π‘ Hint
Remember operator precedence: && has higher precedence than ||, so group accordingly.
β Incorrect
The command groups as: (echo Start && false) || (echo Middle && echo End). 'echo Start' succeeds, then 'false' fails, so left side fails. Right side runs: 'echo Middle' prints, succeeds, so 'echo End' runs and prints.
