Start long-task from the current Bash.
Return to the next prompt without waiting for it to finish.
Which command is appropriate?
A trailing & makes Bash run the command asynchronously. The PID of the most recently started background process is available as $!.
Detailed explanation
long-task &Correct. The trailing & starts long-task in the background and returns the prompt.
Correct. The trailing & starts long-task in the background and returns the prompt.
long-task &&Incorrect. && is conditional execution after success, not background execution.
Incorrect. && is conditional execution after success, not background execution.
long-task |Incorrect. | connects two commands through a pipe; it is incomplete here.
Incorrect. | connects two commands through a pipe; it is incomplete here.
wait long-taskIncorrect. wait synchronizes with a job rather than starting it asynchronously.
Incorrect. wait synchronizes with a job rather than starting it asynchronously.
Try it yourself
An example you can run in a temporary verification environment.
sleep 0.1 & TASK_PID=$!; printf '%s
' "$TASK_PID"; wait "$TASK_PID"Expected result
起動したsleepのPID(正の整数)Key points
- & starts asynchronous execution
- $! is the last background PID
- wait can collect the result
Notes
- Environment: Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.