Objective 3.1XK0-005

3.1 Given a scenario, create simple shell scripts to automate common tasks.

Objective 3.1 sits in Scripting, Containers, and Automation, which carries 19% of the Linux+ exam. The questions below are original, written from the official objective title above, and each explanation cites the CompTIA page it rests on.

Objective title verbatim from the official objectives. CompTIA exam page

A worked example

Shown solved, with the whole explanation open: this is what every question here carries.

3-1Scripting, Containers, and AutomationModerate

An administrator's backup script must proceed only when /srv/data exists as a directory, not as a regular file. Which test guards that correctly?

[ -e /srv/data ]-e is true for any existing path, including a plain file, so it is too broad for a directory-only guard.
[ -d /srv/data ]Correct · your answerCorrect: -d is true when the path exists and is a directory.
[ -f /srv/data ]-f is true only for a regular file, the case the script must reject.
[ -r /srv/data ]-r tests read access, not object type, so a readable file would wrongly pass.

Correct.

Concept

A file test can distinguish that a path exists from the kind of object it names, so a guard checks the specific type it requires rather than mere existence.

Why B

-d is true only when the path exists and is a directory, which is exactly the condition the backup guard needs before it proceeds.

#shell-scripting#conditionals#file-test

Now you: objective 3.1 questions

No account needed. The explanation opens when you answer.

Sample question 1 of 3

3-1Scripting, Containers, and AutomationModerate

A deploy script must abort when the administrator runs it with no first argument. Which condition is true when $1 is empty or unset?

Sample question 2 of 3

3-1Scripting, Containers, and AutomationModerate

An administrator needs a script to branch on whether the previous command succeeded:

$ rsync -a /src/ /dst/
$ echo ???
23

Which special parameter reports that exit status?

Sample question 3 of 3

3-1Scripting, Containers, and AutomationEasy

Which special parameter expands to the number of positional parameters passed to a shell script?

Full Linux+ question bank coming

We’re writing the complete bank from the official objectives right now. Leave your email and we’ll tell you when it ships, nothing else, ever.

Read the sources

These are the official pages the questions above cite. Reading them is studying the objective from the primary source, which is what the explanations point you toward anyway.

More objectives in Scripting, Containers, and Automation