A script must continue only when /etc/app.conf exists and is a regular file, and must stop if that name is a directory or absent. Which test does exactly that?

LPIC-1 Exam 102-500, objective 105. Shells and shell scripting medium

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Correct [ -f /etc/app.conf ]

Correct. -f is true only when the name exists and, after following any symbolic links, refers to a regular file. A directory makes it false.

Not correct [ -e /etc/app.conf ]

Wrong. -e is true for anything that exists, including a directory, a device node or a socket, so it does not exclude the directory case.

Not correct [ -d /etc/app.conf ]

Wrong, and inverted. -d is true precisely when the name is a directory, which is the case the script must reject.

Not correct [ -s /etc/app.conf ]

Wrong. -s tests only that the file exists and has a size greater than zero; it says nothing about the file type, and it rejects a legitimate empty configuration file.

Why

The file-type tests are distinct predicates: -e for existence of any type, -f for a regular file, -d for a directory, -L for a symbolic link, -s for non-zero size, and -r, -w, -x for the caller's access rights. -f already implies existence, so [ -e f ] && [ -f f ] is redundant. Quote the operand when it comes from a variable, because an unquoted empty value collapses the test into a one-argument form that changes its meaning.

Where this comes from

Cited
manual page test(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 105 and space the ones you get wrong.

Practise LPIC-1 Exam 102-500

More questions on this objective

All questions on Shells and shell scripting

Practise LPIC-1 Exam 102-500