0
0
Linux CLIscripting~10 mins

Command chaining (&&, ||, ;) in Linux CLI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run echo Hello only if ls succeeds.

Linux CLI
ls [1] echo Hello
Drag options to blanks, or click blank then click option'
A;
B|
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' runs the second command only if the first fails.
Using ';' runs commands regardless of success.
Using '|' pipes output, not for conditional chaining.
2fill in blank
medium

Complete the code to run echo Failed only if cat file.txt fails.

Linux CLI
cat file.txt [1] echo Failed
Drag options to blanks, or click blank then click option'
A||
B;
C&&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' runs the second command only if the first succeeds.
Using ';' runs commands regardless of success.
Using '|' pipes output, not for conditional chaining.
3fill in blank
hard

Fix the error in the command to run echo Done after mkdir test regardless of success.

Linux CLI
mkdir test [1] echo Done
Drag options to blanks, or click blank then click option'
A;
B||
C&&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' runs second command only on success.
Using '||' runs second command only on failure.
Using '|' pipes output, not for chaining commands.
4fill in blank
hard

Fill both blanks to run echo Success if grep 'hello' file.txt succeeds, else run echo Fail.

Linux CLI
grep 'hello' file.txt [1] echo Success [2] echo Fail
Drag options to blanks, or click blank then click option'
A&&
B||
C;
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using ';' runs all commands regardless of success.
Using '|' pipes output, not for conditional chaining.
Swapping '&&' and '||' changes logic.
5fill in blank
hard

Fill both blanks to run echo Start, then run ls /tmp if echo Start succeeds, else run echo Error.

Linux CLI
; echo Start [1] ls /tmp [2] echo Error
Drag options to blanks, or click blank then click option'
A;
B&&
C||
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Using '|' instead of ';' causes piping, not sequencing.
Mixing order of '&&' and '||' changes logic.
Using only ';' runs all commands regardless of success.