Courseiva

EX200 · domain

Create simple shell scripts

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.

28 questions10 easy8 medium10 hard

Focused practice

Practice Create simple shell scripts questions

Scored sessions drawing only from this domain — pick a length below.

What this domain covers

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 "$@".

Question index

All Create simple shell scripts questions (28)

Click any question to see the full explanation, or start a practice session above.

1

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

Easy
2

A system administrator writes a shell script to monitor disk usage and send an alert if any partition exceeds 80%. Which TWO of the following are best practices for implementing this script?

Easy
3

A script has a syntax error. Which command will help identify the line number of the error without executing the script?

Hard
4

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?

Medium
5

A new intern created a script to display the current user's home directory: #!/bin/bash echo "Home directory: $home" The script outputs 'Home directory: ' with nothing after the colon. What is the most likely cause?

Easy
6

Which TWO of the following are correct statements about exit codes in shell scripts?

Hard
7

A sysadmin writes a shell script /usr/local/bin/check_service.sh that must accept exactly two positional arguments: a service name and a threshold. The script begins with: #!/bin/bash if [ $# -ne 2 ]; then echo "Usage: $0 <service> <threshold>" exit 1 fi An operator runs the script as: ./check_service.sh httpd What is the exit status of the script, and what output is produced?

Medium
8

A system administrator writes the script shown. The /etc directory contains .conf files with spaces in their names (e.g., "my config.conf"). What is the most accurate description of the script's behavior?

Medium
9

A user executes the script shown in the exhibit with './export_script.sh' and then runs 'echo $MY_VAR' in the same terminal. The output is empty. Why does this happen?

Hard
10

Which THREE of the following are common practices to improve the reliability of shell scripts?

Medium
11

A script contains: lines=$(wc -l /etc/passwd); echo $((lines+1)). The output is unexpected. What is the problem?

Easy
12

You maintain a script that performs a long-running task and must clean up temporary files if the script is interrupted. The script uses: #!/bin/bash tempfile=$(mktemp) trap "rm -f $tempfile" EXIT # long task sleep 100 You notice that if the script receives SIGINT (Ctrl+C), the temporary file is not removed. Investigation shows that the trap on EXIT is not executed on SIGINT. Which modification should be made?

Hard
13

Which shell built-in can be used to read user input during script execution?

Medium
14

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?

Hard
15

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?

Easy
16

Which THREE of the following are valid and recommended practices when writing shell scripts for RHEL?

Hard
17

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?

Medium
18

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?

Easy
19

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?

Hard
20

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

Medium
21

A complex script uses 'trap' to handle signals. The admin writes 'trap '' SIGINT' to ignore Ctrl+C, but later in the script they want to re-enable the default behavior. Which command restores the default behavior for SIGINT?

Hard
22

A developer runs the script shown in the exhibit and always sees 'Success' printed, even when the previous command fails. What is the most likely cause?

Medium
23

A script needs to read every line from a file and execute a command on each line. Which code block is correct and handles whitespace correctly?

Easy
24

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?

Easy
25

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

Easy
26

Consider the script in the exhibit. The script is run in a directory containing 'a.txt' and 'b.txt' but also has a subdirectory 'backup' with .txt files. What will be the output?

Easy
27

An organization uses a shell script that runs daily via cron on a central management server to archive logs from 50 remote Red Hat Enterprise Linux servers. The script uses `scp` with SSH key-based authentication (passwordless) to transfer files. Recently, after a security team rotated the SSH host keys on all remote servers, the script started failing with 'Host key verification failed' errors. The administrator needs to restore automated log transfers without compromising security. The remote servers are in a controlled internal network, and the management server's `~/.ssh/known_hosts` file is not centrally managed. Which course of action should the administrator take?

Hard
28

Refer to the exhibit. The script produces the error shown. What is the most likely cause?

Hard

Frequently asked questions

What does the Create simple shell scripts domain cover on the EX200 exam?
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 many questions are in this domain?
This page lists all 28 Create simple shell scripts questions in the EX200 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Create simple shell scripts questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
redhat-rhcsa REDHAT-RHCSA shell scripts Practice Questions