Reconnaissance and Enumeration

A Bash script reads each service banner into $banner and must skip entries where the banner is empty. Which test is true when $banner has zero length?

Show the answer

Correct answerD. [ -z "$banner" ]

AWhy not this: -e tests whether a file path exists, not whether a string is empty.

BWhy not this: -eq is a numeric comparison and fails with an error when the banner holds text.

CWhy not this: -n is true when the string is non-empty, which is the reverse of the needed test.

DWhy this is right: -z is true when the string is zero length, so it matches an empty banner.

The -z string test is true when a string has zero length, which is what an empty banner is. The -n test is the opposite: it is true when the string is non-empty, so it would skip good banners.