During an automated deployment you need a single POSIX-compatible test command that exits with status 0 only when the variable $STAGING_DIR is both non-empty and already points to an existing directory. Which of the following commands satisfies this requirement?
The correct command uses the logical AND operator (&&) to join two test conditions. The -n operator checks that the $STAGING_DIR variable's length is non-zero, and the -d operator checks that it points to an existing directory. The command succeeds only when both conditions are true. Using -z would incorrectly test for an empty string, and -f would test for a regular file instead of a directory. Using the logical OR operator (||) would succeed if either condition were true, not both. Finally, negating -n with ! is the same as using -z; combining this with || would succeed if the variable were empty, which is the opposite of what is required.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the `-n` operator do in a POSIX test command?
Open an interactive chat with Bash
How does the `-d` operator differ from `-f` in POSIX testing?
Open an interactive chat with Bash
Why is the logical AND operator (`&&`) necessary in this command?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access