John works as a Network Administrator for Perfect Solutions Inc. The company has a Linux-based
network. John is working as a root user on the Linux operating system. You want to run two
programs, foo and bar. You also want to ensure that bar is executed if and only if foo has
executed successfully. Which of the following command sequences will John use to accomplish
the task?
A.
foo && bar;
B.
foo | bar;
C.
foo; bar;
D.
foo || bar;
Explanation:
According to the scenario, John will execute the foo && bar; command. Because of the &&
operator, bar will execute if and only if foo completes successfully.
Answer option C is incorrect. The foo; bar; command sequence will run foo and bar in a sequential
manner, but the successful completion of the first command does not matter.
Answer option D is incorrect. The foo || bar; command sequence will run the bar if and only if foo
fails to complete successfully.
Answer option B is incorrect. In the foo | bar; command sequence, the output of the foo command
will be the input for the bar command.