Run second_command after first_command regardless of first_command's exit status.
Write both commands on one command line.
Which list operator is appropriate?
; runs commands in sequence without short-circuiting based on the preceding exit status. && and || conditionally skip the right side.
Detailed explanation
first_command && second_commandIncorrect. && runs the right command only after success.
Incorrect. && runs the right command only after success.
first_command || second_commandIncorrect. || runs the right command only after failure.
Incorrect. || runs the right command only after failure.
first_command | second_commandIncorrect. | connects standard output to standard input.
Incorrect. | connects standard output to standard input.
first_command ; second_commandCorrect. first_command ; second_command runs both in order.
Correct. first_command ; second_command runs both in order.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'false; printf "second\n"'Expected result
secondKey points
- ; always continues
- && means success
- || means failure
Notes
- Environment: POSIX sh / 状態変更なし
- 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.