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.
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?
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.
Now you: objective 3.1 questions
No account needed. The explanation opens when you answer.
Sample question 1 of 3
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
An administrator needs a script to branch on whether the previous command succeeded:
$ rsync -a /src/ /dst/
$ echo ???
23Which special parameter reports that exit status?
Sample question 3 of 3
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.