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.
Start practicing
Create simple shell scripts — choose a session length
Free · No account required
Domain overview
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.
Exam objectives
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
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 "$@".
Click any question to see the full explanation and answer options, or start a focused practice session above.
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?
2Which 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?
3Which TWO of the following are true about creating simple shell scripts in Red Hat Enterprise Linux?
4You 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?
5Arrange the steps to configure a logical volume snapshot named 'snap_lv_data' of logical volume 'lv_data'.
6An administrator writes a script that uses the 'set -e' option at the top. What is the primary effect of this option?
7A 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?
8A 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?
9An 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?
10A 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?
11A 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?
12Which THREE of the following are common practices to improve the reliability of shell scripts?
13Which TWO of the following are correct statements about exit codes in shell scripts?
14Consider 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?
15A 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?
16A 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?
17A script contains: lines=$(wc -l /etc/passwd); echo $((lines+1)). The output is unexpected. What is the problem?
18A script has a syntax error. Which command will help identify the line number of the error without executing the script?
19Which shell built-in can be used to read user input during script execution?
20A 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?
21Which THREE of the following are valid and recommended practices when writing shell scripts for RHEL?
22Refer to the exhibit. The script produces the error shown. What is the most likely cause?
23You 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?
24A 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?
25A 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?
26A 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?
27An 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?
28A 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?
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.
The Courseiva EX200 question bank contains 28 questions in the Create simple shell scripts domain, covering the 11% of the exam attributed to this domain in the official Red Hat blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Create simple shell scripts domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included