ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 19 - XK0-005 discussion

Report
Export

A user is asking the systems administrator for assistance with writing a script to verify whether a file exists. Given the following:

Which of the following commands should replace the <CONDITIONAL> string?

A.
if [ -f "$filename" ]; then
Answers
A.
if [ -f "$filename" ]; then
B.
if [ -d "$filename" ]; then
Answers
B.
if [ -d "$filename" ]; then
C.
if [ -f "$filename" ] then
Answers
C.
if [ -f "$filename" ] then
D.
if [ -f "$filename" ]; while
Answers
D.
if [ -f "$filename" ]; while
Suggested answer: A

Explanation:

The command if [ -f "$filename" ]; then checks if the variable $filename refers to a regular file that exists. The -f option is used to test for files. If the condition is true, the commands after then are executed. This is the correct way to replace the <CONDITIONAL> string. The other options are incorrect because they either use the wrong option (-d tests for directories), the wrong syntax (missing a semicolon after the condition), or the wrong keyword (while is used for loops, not conditions). Reference: CompTIA Linux+ (XK0-005) Certification Study Guide, Chapter 16: Writing and Executing Bash Shell Scripts, page 493.

asked 02/10/2024
Dimitri Bennett
35 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first