Courseiva

EX200 · topic practice

Create simple shell scripts practice questions

This domain covers writing and debugging Bash shell scripts on RHEL: shebangs, variables and quoting, positional parameters, conditionals, loops, exit codes, and command substitution. EX200 tests it through exhibit-based questions where you inspect a script, predict its output or error, and choose the correct construct or fix.

Courseiva uses original exam-style practice questions designed for learning and revision. The goal is to understand the concepts, recognise exam patterns, and improve through explanations — not memorise copied exam dumps.

Editorial oversight:Johnson Ajibi· MSc IT Security, IEEE Senior Member
20 questionsDomain: Create simple shell scripts

What the exam tests

What to know about Create simple shell scripts

Write a Bash script that reads arguments, uses conditionals and loops, and exits with a meaningful status. The single most important thing: understand that a script runs in a child process, so its variables do not persist in your interactive shell unless you source it or export them.

Shebang lines, script permissions, and executing scripts with bash versus ./script.sh

Variable scope: exported variables versus shell-local variables and subshell behavior

Positional parameters like $1, $#, and $@, plus default values using parameter expansion

Loop constructs: for over lists, while read for files, and if/then/else conditionals

Watch out for

Common Create simple shell scripts exam traps

  • ▸Running a script with ./script.sh sets variables only in its child shell, so the parent shell's echo shows nothing unless the script is sourced or the variable exported.
  • ▸Forgetting the shebang or execute permission, causing 'Permission denied' or the script running under an unexpected interpreter.
  • ▸Unquoted variables containing spaces or globs split into multiple arguments or expand unexpectedly; always quote "$var" and "$@".

Practice set

Create simple shell scripts questions

20 questions · select your answer, then reveal the explanation

A system administrator needs to create a shell script that checks if the user 'jdoe' exists in the system and, if not, creates the user with a home directory. The script should also verify that the creation was successful. Which of the following script snippets correctly implements this logic?

Refer to the exhibit. A junior admin runs this script as root, but it always prints 'httpd is running' even when httpd is stopped. What is the most likely cause?

Network Topology
if systemctl is-activequiet $SERVICERefer to the exhibit.```bash#!/bin/bash# Script: check_service.shSERVICE="httpd"thenecho "$SERVICE is running"elsesystemctl restart $SERVICEecho "$SERVICE was restarted"fi```

You are a system administrator for a medium-sized company running Red Hat Enterprise Linux 8 on all servers. The development team has created a shell script that is supposed to be run nightly via cron to synchronize configuration files from a master server to multiple web servers. The script is located at /opt/scripts/sync_configs.sh and is owned by root. It uses rsync over SSH with key-based authentication. The script works perfectly when run manually by root, but when it runs via cron, the synchronization fails with the error 'Host key verification failed.' The script does not explicitly specify any SSH options. The cron job is configured in /etc/crontab as: `0 2 * * * root /opt/scripts/sync_configs.sh`. The SSH keys are stored in /root/.ssh/id_rsa and the known_hosts file contains the correct host key for the master server. What is the most likely cause of the failure, and what is the best course of action to resolve it?

Match each package management command to its action.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Install a package with dependencies

Uninstall a package

Update all packages to latest versions

Show all installed packages

A junior admin writes a script that uses functions. They notice that a variable set inside a function is not available after the function call. What is the likely cause and best practice?

A sysadmin creates a script to rotate log files. The script uses 'find /var/log -type f -name "*.log" -mtime +30 -exec gzip {} \;' but some log files are not compressed. The script runs as root. What is the most likely reason some files remain uncompressed?

A script uses 'read' to get user input and then performs an action based on the input. However, when the script is piped (e.g., './script.sh | othercommand'), the read command does not wait for input and the script continues with empty variable. How can this be fixed?

Which TWO of the following are valid ways to make a shell script executable?

Which TWO methods correctly create a variable containing the number of regular files in the current directory (excluding . and ..)?

You are tasked with creating a script that reads a list of usernames from /tmp/users.txt, one per line, and creates a home directory for each user using `mkdir /home/$username`. The script is:

#!/bin/bash

while read username; do

mkdir /home/$username done < /tmp/users.txt

However, the script fails for usernames that contain spaces (e.g., 'john smith'). The error is 'mkdir: cannot create directory '/home/john': File exists' and then a separate directory for 'smith'. What is the best fix?

A developer wrote a shell script that is intended to back up log files by copying all .log files from /var/log/myapp to /backup/logs. The script runs daily via cron but the backup folder is empty. The script contains the following line: `cp /var/log/myapp/*.log /backup/logs/`. What is the most likely reason the backup fails?

Which THREE of the following practices are recommended when creating simple shell scripts in a Red Hat Enterprise Linux environment to ensure reliability, security, and maintainability?

Which TWO of the following are true about creating simple shell scripts in Red Hat Enterprise Linux?

You are a system administrator for a small company. The development team has created a shell script named 'deploy.sh' that automates deployment of a web application. The script is located at /home/devops/deploy.sh. The team reports that when they run the script with './deploy.sh' from the /home/devops directory, it fails with a 'Permission denied' error. However, running 'bash deploy.sh' works fine. Additionally, the script's first line is '#!/bin/bash' and the file permissions are '-rw-rw-r--'. The team wants to be able to run the script directly without typing 'bash'. Which of the following actions should you take to resolve the issue?

Arrange the steps to configure a logical volume snapshot named 'snap_lv_data' of logical volume 'lv_data'.

Drag or tap steps into the slots.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

An administrator writes a script that uses the 'set -e' option at the top. What is the primary effect of this option?

A system administrator needs to create a shell script that processes a list of hostnames stored in a file, one per line, and runs a command on each host. Which loop construct is most appropriate?

A developer wants to create a script that accepts a directory path as an argument and creates a timestamped backup of that directory. If no argument is provided, it should back up the current directory. How should the script handle the argument?

An administrator writes a script to check disk usage and send an alert if usage exceeds 80%. The script uses 'df -h /' and parses the output. To maintain portability and avoid common pitfalls, which approach is recommended?

A script needs to execute a command that might fail, but the script should continue. The administrator wants to capture the exit status for logging. Which code snippet correctly implements this?

Free account

Track your progress over time

Create a free account to save your results and see which topics improve across sessions.

Focused Create simple shell scripts sessions

Start a Create simple shell scripts only practice session

Every question in these sessions is drawn from the Create simple shell scripts domain — nothing else.

Related practice questions

Related EX200 topic practice pages

Move into related areas when this topic feels solid.

Frequently asked questions

What does the EX200 exam test about Create simple shell scripts?
Write a Bash script that reads arguments, uses conditionals and loops, and exits with a meaningful status. The single most important thing: understand that a script runs in a child process, so its variables do not persist in your interactive shell unless you source it or export them.
How should I use these practice questions?
Select your answer before revealing the explanation. Then read why each option is right or wrong — this active recall approach builds retention far faster than re-reading notes.
Can I practise just Create simple shell scripts questions in a focused session?
Yes — the session launcher on this page draws every question from the Create simple shell scripts domain. Use a 10-question session first to gauge your baseline, then move to 20 or 30 once the weak spots are clear.
Where can I practise other EX200 topics?
Use the topic links above to move to related areas, or go back to the EX200 question bank to see all topics.
Are these real exam questions or dumps?
These are original practice questions written to test the same concepts the EX200 exam covers. They are not copied from any real exam or dump site.