0
0
Bash Scriptingscripting~10 mins

Subshells (command grouping) in Bash Scripting - 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 two commands in a subshell.

Bash Scripting
(echo "Hello" [1] echo "World")
Drag options to blanks, or click blank then click option'
A&&
B;
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' will run the second command only if the first succeeds.
Using '|' pipes output, not just separates commands.
Using '&' runs commands in background, not sequentially.
2fill in blank
medium

Complete the code to capture the output of commands run in a subshell.

Bash Scripting
result=$(echo "Start" [1] echo "End")
Drag options to blanks, or click blank then click option'
A&
B&&
C|
D;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' may skip second command if first fails.
Using '|' pipes output, changing what is captured.
Using '&' runs commands in background, output may be lost.
3fill in blank
hard

Fix the error in the code to run commands in a subshell and redirect output.

Bash Scripting
(cd /tmp [1] ls) > output.txt
Drag options to blanks, or click blank then click option'
A;
B&&
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' may skip 'ls' if 'cd' fails.
Using '|' pipes output, changing behavior.
Using '&' runs commands in background, output redirection may fail.
4fill in blank
hard

Fill both blanks to run commands in a subshell and combine outputs.

Bash Scripting
(echo "User:" [1] whoami [2] echo "Done")
Drag options to blanks, or click blank then click option'
A;
B&&
C|
D&
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&&' skips commands if previous fails.
Using '|' pipes output, changing flow.
Using '&' runs commands in background, not sequentially.
5fill in blank
hard

Fill all three blanks to create a dictionary-like output with command grouping and condition.

Bash Scripting
output=$( { echo "Start" [1] if [[ -f /etc/passwd ]]; then echo "File exists" [2] else echo "No file"; fi [3] echo "End"; } )
Drag options to blanks, or click blank then click option'
A;
B&&
D|
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting semicolons causes syntax errors.
Using '&&' changes flow to conditional execution.
Using '|' pipes output, not suitable here.