nerdexam
GIAC

GSNA · Question #302

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…

The correct answer is D. foo && bar. 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: A is incorrect. The foo; bar; command sequence will run foo and bar in a sequential manner, but the successful…

Linux/Unix System Auditing

Question

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?

Options

  • Afoo; bar;
  • Bfoo || bar;
  • Cfoo | bar;
  • Dfoo && bar;

How the community answered

(48 responses)
  • A
    8% (4)
  • B
    17% (8)
  • C
    4% (2)
  • D
    71% (34)

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: A 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: B is incorrect. The foo || bar; command sequence will run the bar if and only if foo fails to complete successfully. Answer: C is incorrect. In the foo | bar; command sequence, the output of the foo command will be the input for the bar command.

Topics

#bash scripting#conditional execution#&& operator#Linux commands

Community Discussion

No community discussion yet for this question.

Full GSNA Practice