nerdexam
CompTIA

XK0-006 · Question #70

A systems administrator needs to write a script that counts the number of times "FAIL" appears in a log file. If "FAIL" appears zero times, then the administrator would like to print the message…

The correct answer is D. -eq. The test should check if the count of "FAIL" equals zero. The operator -eq is used for numeric equality in shell conditionals, so [ $(grep -c FAIL /var/file.log) -eq 0 ] correctly evaluates whether the count is zero.

Automation, Orchestration, and Scripting

Question

A systems administrator needs to write a script that counts the number of times “FAIL” appears in a log file. If “FAIL” appears zero times, then the administrator would like to print the message “SUCCESS.” Given the following:

Which of the following should be used before the zero to complete the script?

Exhibit

XK0-006 question #70 exhibit

Options

  • A-ne
  • B-gt
  • C-lt
  • D-eq

How the community answered

(49 responses)
  • A
    6% (3)
  • B
    2% (1)
  • C
    4% (2)
  • D
    88% (43)

Explanation

The test should check if the count of "FAIL" equals zero. The operator -eq is used for numeric equality in shell conditionals, so [ $(grep -c FAIL /var/file.log) -eq 0 ] correctly evaluates whether the count is zero.

Topics

#bash scripting#comparison operators#conditional logic#-eq

Community Discussion

No community discussion yet for this question.

Full XK0-006 Practice