What does adding an ampersand (&) at the end of a command do in bash?
It runs the command in the background, allowing you to continue using the terminal without waiting for the command to finish.
Click to reveal answer
beginner
How can you check the list of background jobs running in your current shell session?
Use the jobs command to see all background jobs with their job numbers and status.
Click to reveal answer
beginner
What is the difference between running a command normally and running it with & in bash?
Normally, the shell waits for the command to finish before accepting new input. With &, the shell starts the command and immediately returns control to you.
Click to reveal answer
intermediate
How do you bring a background job back to the foreground in bash?
Use the fg command followed by the job number, for example fg %1 to bring job 1 to the foreground.
Click to reveal answer
beginner
Why might running commands in the background be useful?
It lets you keep working in the terminal while long tasks run without blocking your input, like downloading files or running scripts.
Click to reveal answer
What symbol do you add at the end of a bash command to run it in the background?
A*
B#
C$
D&
✗ Incorrect
The ampersand (&) runs the command in the background.
Which command lists all background jobs in the current shell?
Ajobs
Bps
Cbg
Dfg
✗ Incorrect
The 'jobs' command shows all background jobs.
How do you bring a background job with job number 2 to the foreground?
Ajobs %2
Bbg %2
Cfg %2
Dkill %2
✗ Incorrect
Use 'fg %2' to bring job 2 to the foreground.
What happens if you run a command without & at the end?
AIt runs in the background
BIt runs in the foreground and blocks the terminal until done
CIt runs twice
DIt runs with higher priority
✗ Incorrect
Without &, the command runs in the foreground and blocks the terminal.
Why would you want to run a command in the background?
ATo run multiple commands at once without waiting
BTo save the command output
CTo make the command faster
DTo stop the command
✗ Incorrect
Running in background lets you run multiple commands without waiting.
Explain how to run a command in the background and how to check its status.
Think about how you keep working while a task runs.
You got /2 concepts.
Describe how to bring a background job back to the foreground and why you might do that.
Sometimes you want to control a running task again.
You got /3 concepts.
Practice
(1/5)
1. What does adding & at the end of a command in bash do?
easy
A. Runs the command in the background, freeing the terminal immediately
B. Stops the command from running
C. Runs the command with higher priority
D. Runs the command only if another command fails
Solution
Step 1: Understand the role of & in bash
The & symbol placed after a command tells bash to run that command in the background.
Step 2: Effect on terminal usability
Running a command in the background frees the terminal immediately so you can type new commands without waiting.
Final Answer:
Runs the command in the background, freeing the terminal immediately -> Option A
Quick Check:
Background run = frees terminal [OK]
Hint: Remember: & means run in background and free terminal [OK]
Common Mistakes:
Thinking & stops the command
Confusing & with command priority
Assuming & waits for command to finish
2. Which of the following is the correct syntax to run sleep 10 in the background?
easy
A. sleep 10 &&
B. sleep 10 &
C. sleep & 10
D. & sleep 10
Solution
Step 1: Identify correct placement of &
The & must come immediately after the full command to run it in the background.
Step 2: Check each option
sleep 10 & places & correctly after sleep 10. The other options misuse & or use wrong symbols.
Final Answer:
sleep 10 & -> Option B
Quick Check:
Command & = correct syntax [OK]
Hint: Put & at the end of the command line [OK]
Common Mistakes:
Placing & before the command
Inserting & between command and arguments
Using && instead of &
3. What will be the output of the following commands?
echo "Start"
sleep 3 &
echo "End"
medium
A. Only Start is printed
B. Start\n(wait 3 seconds)\nEnd
C. Start\nEnd (immediately), then sleep runs silently
D. Start\nEnd\nError message
Solution
Step 1: Analyze command order and background execution
The sleep 3 & runs in the background, so it does not block the terminal.
Step 2: Understand output timing
"Start" prints first, then sleep 3 & starts silently in background, then "End" prints immediately.
Final Answer:
Start\nEnd (immediately), then sleep runs silently -> Option C
Quick Check:
Background sleep = immediate End print [OK]
Hint: Background commands don't block output [OK]
Common Mistakes:
Expecting sleep to delay 'End' output
Thinking background commands print output
Confusing & with && causing wait
4. Identify the error in this script snippet:
echo "Start"
sleep 5 &
wait
wait
echo "Done"
medium
A. The echo command should be before wait
B. Using two wait commands causes an error
C. Missing & after sleep 5
D. The second wait is redundant but not an error
Solution
Step 1: Understand wait behavior
The wait command waits for all background jobs to finish. Multiple wait commands do not cause errors but the second is unnecessary.
Step 2: Check script correctness
The script runs sleep 5 in background, waits twice, then prints "Done". This works but the second wait is redundant.
Final Answer:
The second wait is redundant but not an error -> Option D
Quick Check:
Multiple waits allowed, redundant but no error [OK]
Hint: Multiple waits don't error, just wait again [OK]
Common Mistakes:
Thinking multiple waits cause errors
Forgetting & after sleep
Misplacing echo before wait
5. You want to run three commands cmd1, cmd2, and cmd3 in the background simultaneously, then wait for all to finish before printing "All done". Which script correctly does this?
hard
A. cmd1 &
cmd2 &
cmd3 &
wait
echo "All done"
B. cmd1 & cmd2 & cmd3 & wait &
echo "All done"
C. cmd1 & cmd2 & cmd3
echo "All done"
D. cmd1 & cmd2 & cmd3 &
echo "All done"
Solution
Step 1: Run each command in background separately
Each command must end with & to run in background independently.
Step 2: Use wait to pause until all background jobs finish
After starting all commands, wait pauses script until all finish, then prints "All done".
Final Answer:
cmd1 &
cmd2 &
cmd3 &
wait
echo "All done" -> Option A
Quick Check:
Separate & + wait before echo = correct [OK]
Hint: Put & after each command, then wait once [OK]
Common Mistakes:
Running all commands on one line without separate &
Omitting wait causing early echo
Placing echo on same line as background commands
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.