Challenge - 5 Problems
Background Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this background command?
Consider the following bash command run in a terminal:
What will be printed immediately after running this command?
sleep 2 & echo "Done"What will be printed immediately after running this command?
Bash Scripting
sleep 2 & echo "Done"
Attempts:
2 left
💡 Hint
The ampersand (&) runs the first command in the background, so the next command runs immediately.
✗ Incorrect
The command 'sleep 2 &' runs sleep in the background, so the shell immediately runs 'echo "Done"' which prints 'Done'.
💻 Command Output
intermediate1:30remaining
What happens if you run multiple background commands?
What will be the output of this script?
Choose the correct output order.
echo Start
sleep 1 &
sleep 2 &
echo EndChoose the correct output order.
Bash Scripting
echo Start sleep 1 & sleep 2 & echo End
Attempts:
2 left
💡 Hint
Background commands do not produce output unless they have their own output commands.
✗ Incorrect
Only 'echo' commands produce output here. 'sleep' commands run silently in background. So output is 'Start' then 'End'.
🔧 Debug
advanced2:00remaining
Why does this background command fail to run?
Look at this command:
It gives an error: 'my_script.sh: command not found'. Why?
my_script.sh &It gives an error: 'my_script.sh: command not found'. Why?
Bash Scripting
my_script.sh &
Attempts:
2 left
💡 Hint
Check if the script file has execute permission and is in the current directory or PATH.
✗ Incorrect
The error means the shell cannot find 'my_script.sh' as a command. Usually because it's not executable or not in PATH.
🚀 Application
advanced2:00remaining
How to run a command in background and save its output to a file?
You want to run
long_task.sh in background and save its output to output.log. Which command does this correctly?Attempts:
2 left
💡 Hint
Redirect output before the ampersand to capture it.
✗ Incorrect
Redirecting output with > before & sends output to file while running command in background.
🧠 Conceptual
expert2:30remaining
What is the effect of running a pipeline with background (&)?
Consider this command:
What happens when you run it?
cat file.txt | grep 'hello' &What happens when you run it?
Attempts:
2 left
💡 Hint
The ampersand puts the entire pipeline in background.
✗ Incorrect
The & at the end runs the entire pipeline in background. Output still goes to terminal unless redirected.