nerdexam
CompTIA

XK0-005 · Question #1128

An analyst is trying to determine which public IP addresses are managed by Company A, but the script is not working correctly. Which of the following explains what is wrong with the script?

The correct answer is D. The -ne flag should be changed to -eq in the if statement. The error is that the -ne flag (not equal) should be changed to -eq (equal) in the if statement. In the context of this script - which likely runs whois or a similar lookup against a list of IPs and checks whether the output matches 'Company A' - the condition logic is…

Scripting, Containers, and Automation

Question

An analyst is trying to determine which public IP addresses are managed by Company A, but the script is not working correctly. Which of the following explains what is wrong with the script?

Exhibit

XK0-005 question #1128 exhibit

Options

  • A$(cat ip-list.txt) should be changed to cat ip-list.txt in the for statement.
  • BThe for should be changed to while in the loop.
  • CThe > should be changed to 2> in the do statement.
  • DThe -ne flag should be changed to -eq in the if statement.

How the community answered

(22 responses)
  • A
    9% (2)
  • B
    5% (1)
  • C
    5% (1)
  • D
    82% (18)

Explanation

The error is that the -ne flag (not equal) should be changed to -eq (equal) in the if statement. In the context of this script - which likely runs whois or a similar lookup against a list of IPs and checks whether the output matches 'Company A' - the condition logic is inverted. Using -ne would cause the script to process IPs that do NOT match Company A and skip ones that do, producing the opposite of the intended result. Option A is incorrect because both $() and backtick syntax are valid for command substitution. Option B is incorrect because a for loop iterating over file contents is a standard and correct pattern. Option C is incorrect because > redirects stdout to a file, and 2> redirects stderr; changing this would affect error output, not the filtering logic. The logical operator (-ne vs -eq) is the root cause of the incorrect filtering.

Topics

#Shell Scripting#Conditional Statements#Comparison Operators#Script Debugging

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice