Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Multi-function scripting · Easy
What is the main purpose of using functions in a Bash script?
Not quite. Try another option.
Answer: To organize reusable commands
Functions group related commands so they can be reused within a script.
Question 2 of 60 · Multi-function scripting · Easy
Which syntax correctly calls a Bash function named backup_files?
Not quite. Try another option.
Answer: backup_files
A Bash function is called by writing its name as a command.
Question 3 of 60 · Interactive menu with colors · Easy
Which Bash command is commonly used to read a user's menu choice?
Not quite. Try another option.
Answer: read
The read command accepts input from the user and stores it in a variable.
Question 4 of 60 · Interactive menu with colors · Easy
What is commonly used to display colored text in a Bash menu?
Not quite. Try another option.
Answer: ANSI escape codes
ANSI escape codes control terminal text properties such as color and style.
Question 5 of 60 · Remote script execution · Easy
Which command is commonly used to execute commands securely on a remote Linux server?
Not quite. Try another option.
Answer: ssh
ssh creates a secure connection through which remote commands can be executed.
Question 6 of 60 · Remote script execution · Easy
In the command ssh admin@example.com, what does admin represent?
Not quite. Try another option.
Answer: The remote username
The value before @ is the account name used to log in to the remote host.
Question 7 of 60 · Working with JSON via jq · Easy
What is jq primarily used for in shell scripts?
Not quite. Try another option.
Answer: Processing JSON data
jq is a command-line tool for reading, filtering, and transforming JSON.
Question 8 of 60 · Working with JSON via jq · Easy
Which command extracts the name field from data.json using jq?
Not quite. Try another option.
Answer: jq '.name' data.json
The filter .name selects the value associated with the name key.
Question 9 of 60 · Cloudflare API integration · Easy
What does an API token provide when a script accesses the Cloudflare API?
Not quite. Try another option.
Answer: Authentication and permissions
An API token identifies the request and limits which Cloudflare resources it may access.
Question 10 of 60 · Cloudflare API integration · Easy
Which command-line tool is commonly used to send HTTP requests to the Cloudflare API?
Not quite. Try another option.
Answer: curl
curl can send HTTP requests, headers, and data to web APIs.
Question 11 of 60 · Access log summarizer · Easy
What information is commonly recorded in a web server access log?
Not quite. Try another option.
Answer: Client requests and status codes
Access logs normally record requests, client addresses, timestamps, and HTTP status codes.
Question 12 of 60 · Access log summarizer · Easy
Which command is useful for counting lines in an access log?
Not quite. Try another option.
Answer: wc -l
wc -l reports the number of lines in a file or input stream.
Question 13 of 60 · Sending emails with SSMTP · Easy
What is SSMTP used for in a Bash automation script?
Not quite. Try another option.
Answer: Sending email messages
SSMTP forwards email messages from scripts or command-line tools to an SMTP server.
Question 14 of 60 · Sending emails with SSMTP · Easy
Which piece of information identifies the server used to send email through SSMTP?
Not quite. Try another option.
Answer: SMTP host address
The SMTP host address tells SSMTP which mail server should receive outgoing messages.
Question 15 of 60 · Password generator · Easy
Which property is most important for passwords created by an automated generator?
Not quite. Try another option.
Answer: They should be unpredictable
Unpredictable passwords are harder for attackers to guess or reproduce.
Question 16 of 60 · Password generator · Easy
Which Linux source can provide random bytes for a Bash password generator?
Not quite. Try another option.
Answer: /dev/urandom
/dev/urandom supplies random bytes that can be filtered into password characters.
Question 17 of 60 · Pipes versus redirection · Easy
What does the pipe operator | do in Bash?
Not quite. Try another option.
Answer: Sends one command's output to another
A pipe connects the standard output of one command to the standard input of the next.
Question 18 of 60 · Pipes versus redirection · Easy
What does > do in the command date > today.txt?
Not quite. Try another option.
Answer: Writes output to the file
> redirects standard output to a file and replaces the file's existing contents.
Question 19 of 60 · Automated WordPress setup on LAMP stack · Easy
In the term LAMP, what does the letter A represent?
Not quite. Try another option.
Answer: Apache
LAMP commonly stands for Linux, Apache, MySQL or MariaDB, and PHP.
Question 20 of 60 · Automated WordPress setup on LAMP stack · Easy
Why does an automated WordPress setup script create a database?
Not quite. Try another option.
Answer: To store WordPress content and settings
WordPress uses a database to store posts, users, configuration values, and other site data.
Question 21 of 60 · Multi-function scripting · Medium
A Bash script defines backup_files() and show_usage(). Which approach correctly calls show_usage when the user supplies no command-line arguments?
Not quite. Try another option.
Answer: [[ $# -eq 0 ]] && show_usage
$# contains the number of command-line arguments. If it is zero, the script can call show_usage.
Question 22 of 60 · Multi-function scripting · Medium
A function must calculate a directory size and make that value available to the calling code. Which implementation is most suitable for command substitution?
Not quite. Try another option.
Answer: get_size() { du -sh "$1" | cut -f1; }
Command substitution captures standard output, so the function should print the calculated value. return is intended for numeric exit statuses from 0 to 255.
Question 23 of 60 · Interactive menu with colors · Medium
An interactive Bash menu prints colored choices, but text entered afterward remains green. Which change should be made after printing each colored line?
Not quite. Try another option.
Answer: Print the ANSI reset sequence \e[0m
The ANSI sequence \e[0m resets terminal formatting, preventing the selected color from affecting later output.
Question 24 of 60 · Interactive menu with colors · Medium
Which Bash structure most directly handles menu choices such as 1, 2, and q while also providing a response for invalid input?
Not quite. Try another option.
Answer: A case statement with a * pattern
A case statement matches each valid choice, while the * pattern acts as the fallback for unrecognized input.
Question 25 of 60 · Remote script execution · Medium
A local script named audit.sh must run on server1 without first being copied to a remote file. Which command sends it through SSH correctly?
Not quite. Try another option.
Answer: ssh admin@server1 'bash -s' < audit.sh
SSH starts bash -s remotely, and input redirection supplies the local script through the SSH connection.
Question 26 of 60 · Remote script execution · Medium
A remote command contains $HOSTNAME, which must be expanded by the remote shell rather than the local shell. Which command preserves it until remote execution?
Not quite. Try another option.
Answer: ssh user@host 'echo $HOSTNAME'
Single quotes prevent the local shell from expanding $HOSTNAME, allowing the remote shell to expand it instead.
Question 27 of 60 · Working with JSON via jq · Medium
Given {"users":[{"name":"Ana","active":true},{"name":"Ben","active":false}]}, which jq filter prints only the name of each active user?
.users[] iterates over the user objects, select keeps active users, and .name extracts their names.
Question 28 of 60 · Working with JSON via jq · Medium
A script stores an API response in response and needs the raw string value of its .id field without JSON quotation marks. Which command should it use?
Not quite. Try another option.
Answer: id=$(jq -r '.id' <<< "$response")
The -r option emits strings as raw text, which is appropriate when assigning an API field to a shell variable.
Question 29 of 60 · Cloudflare API integration · Medium
A script updates a Cloudflare DNS record through the API. Which combination should normally appear in the authenticated HTTP request?
Not quite. Try another option.
Answer: Authorization: Bearer TOKEN and Content-Type: application/json
Cloudflare API tokens are normally sent using the Bearer authorization scheme, and DNS record request bodies use JSON.
Question 30 of 60 · Cloudflare API integration · Medium
Before updating a Cloudflare DNS record, a script queries records by name. Why should it extract the record ID from the response?
Not quite. Try another option.
Answer: The update endpoint identifies the record by its record ID
Cloudflare's update request targets a specific DNS record resource, so its record ID is required in the endpoint path.
Question 31 of 60 · Access log summarizer · Medium
In a standard combined Apache access log, the client IP address is the first whitespace-separated field. Which pipeline lists the ten most frequent client IPs?
The IPs must first be sorted so uniq -c can count adjacent duplicates. Numeric reverse sorting then places the highest counts first.
Question 32 of 60 · Access log summarizer · Medium
An Apache log uses combined log format, where the quoted request is fields 6 through 8 and the status code is field 9. Which command counts only HTTP 404 responses?
Not quite. Try another option.
Answer: awk '$9 == 404 {count++} END {print count}' access.log
In combined log format, $9 is the status field. The == operator compares it with 404 without modifying the record.
Question 33 of 60 · Sending emails with SSMTP · Medium
A Bash script creates a complete email containing To: and Subject: headers in message.txt. Which command submits it through SSMTP?
Not quite. Try another option.
Answer: ssmtp recipient@example.com < message.txt
SSMTP reads the message from standard input, so < message.txt supplies the message while the address specifies the recipient.
Question 34 of 60 · Sending emails with SSMTP · Medium
A scheduled backup script should send an email only when backup.sh fails. Which condition correctly triggers the SSMTP command?
Not quite. Try another option.
Answer: if ! ./backup.sh; then ssmtp ops@example.com < failure.txt; fi
The ! operator makes the condition succeed when backup.sh returns a nonzero exit status, which conventionally indicates failure.
Question 35 of 60 · Password generator · Medium
Which command generates a 20-character password from letters, digits, and selected symbols using random bytes from the operating system?
tr -dc removes bytes outside the allowed set, and head -c 20 limits the result to exactly 20 characters.
Question 36 of 60 · Password generator · Medium
A password script uses random=$RANDOM$RANDOM and then truncates the result. What is the main security weakness of this approach?
Not quite. Try another option.
Answer: $RANDOM has limited state and is not cryptographically secure
Bash's $RANDOM is suitable for simple scripting tasks but is predictable compared with a cryptographically secure random source.
Question 37 of 60 · Pipes versus redirection · Medium
Which statement correctly describes producer | consumer > result.txt?
Not quite. Try another option.
Answer: The pipe sends producer output to consumer, then redirection saves consumer output
The pipe connects the producer's standard output to the consumer's standard input. > then writes the consumer's output to the file.
Question 38 of 60 · Pipes versus redirection · Medium
A script must save both standard output and standard error from deploy.sh into deploy.log. Which Bash command performs this correctly?
Not quite. Try another option.
Answer: ./deploy.sh > deploy.log 2>&1
The command first redirects standard output to the log, then redirects standard error to the same destination as standard output.
Question 39 of 60 · Automated WordPress setup on LAMP stack · Medium
During an automated WordPress installation, which database setup follows the principle of least privilege?
Not quite. Try another option.
Answer: Create a dedicated database user and grant it rights only on the WordPress database
A dedicated user restricted to the WordPress database limits damage if the application's database credentials are exposed.
Question 40 of 60 · Automated WordPress setup on LAMP stack · Medium
An installation script may be run more than once. Which design best makes the WordPress database creation step idempotent?
Not quite. Try another option.
Answer: Use CREATE DATABASE IF NOT EXISTS and conditionally create the application user
Idempotent automation checks or safely tolerates existing resources, allowing repeated runs without destroying data or creating duplicates.
Question 41 of 60 · Multi-function scripting · Hard
A Bash function must compute a value for command substitution while also reporting diagnostics. Which implementation preserves the computed output in result=$(calculate) without mixing diagnostics into it?
Command substitution captures standard output. Sending diagnostics to standard error keeps the function's data output clean; return communicates only an exit status from 0 to 255.
Question 42 of 60 · Multi-function scripting · Hard
A script enables set -e and defines an ERR trap, but failures inside called functions do not consistently trigger the trap. Which additional setting makes the ERR trap inherited by shell functions, command substitutions, and subshells?
Not quite. Try another option.
Answer: set -E
set -E, also called errtrace, causes the ERR trap to be inherited in functions, command substitutions, and subshell environments. It does not remove the documented contextual exceptions of set -e.
Question 43 of 60 · Interactive menu with colors · Hard
An interactive colored menu is also executed by cron, where its output is redirected to a log. Which condition should control whether ANSI color sequences are emitted?
Not quite. Try another option.
Answer: [[ -t 1 ]] before emitting colors
[[ -t 1 ]] tests whether standard output is attached to a terminal. This prevents escape sequences from polluting redirected logs while retaining color in an interactive terminal.
Question 44 of 60 · Interactive menu with colors · Hard
A menu temporarily disables terminal echo while reading a secret. Pressing Ctrl+C sometimes leaves the terminal unusable and colored output unreset. Which design most reliably restores both states?
Not quite. Try another option.
Answer: Install an EXIT INT TERM trap that restores stty echo and prints the reset sequence
A cleanup trap runs during normal termination and handled signals, allowing terminal echo and color state to be restored even when input is interrupted.
Question 45 of 60 · Remote script execution · Hard
A local script must pass an arbitrary argument, including spaces and shell metacharacters, to bash -s on a remote Bash host. Which pattern safely constructs the remote command?
printf '%q' produces a Bash-escaped representation before SSH sends the command string. Direct interpolation or separate-looking SSH arguments can be reparsed by the remote shell and lose argument boundaries.
Question 46 of 60 · Remote script execution · Hard
The command ssh host 'sudo bash -s' < deploy.sh hangs because remote sudo requests a password while standard input already carries the script. For unattended automation, which change is most appropriate?
Not quite. Try another option.
Answer: Use sudo -n bash -s and configure narrowly scoped passwordless sudo
sudo -n fails instead of prompting, which makes automation deterministic. A narrowly scoped sudoers rule avoids embedding credentials or mixing password input with script content.
Question 47 of 60 · Working with JSON via jq · Hard
Given an array of request objects, which jq filter returns one object mapping each HTTP status to its occurrence count, such as {"200": 8, "404": 2}?
group_by requires input sorted by the grouping expression. Each group is converted to a {key, value} entry, and from_entries builds the final object.
Question 48 of 60 · Working with JSON via jq · Hard
A shell variable name may contain quotes, newlines, or backslashes. Which command safely creates the JSON object {"name": <value>} without manual escaping?
Not quite. Try another option.
Answer: jq -n --arg name "$name" '{name: $name}'
--arg passes the shell value as a properly encoded JSON string. Interpolating it into JSON text or using printf does not safely escape arbitrary content.
Question 49 of 60 · Cloudflare API integration · Hard
A script calls the Cloudflare API with curl, and an HTTP 400 response still leaves curl with exit status 0. Which invocation best lets the script capture the JSON error body while also treating HTTP errors as command failures?
--fail-with-body returns a failure status for HTTP errors while preserving the response body for Cloudflare's structured error details. Plain --fail commonly suppresses that body.
Question 50 of 60 · Cloudflare API integration · Hard
A zone has more DNS records than the API's per_page limit. Which termination condition correctly drives a pagination loop using Cloudflare's result_info metadata?
Not quite. Try another option.
Answer: Continue while .result_info.page < .result_info.total_pages
page and total_pages directly indicate whether another page exists. Page result counts can vary, and success only describes the current request.
Question 51 of 60 · Access log summarizer · Hard
In a standard combined access log, the request and user-agent fields contain spaces inside quotes. Which strategy most reliably counts response status codes without assuming that every whitespace-separated field has a fixed position?
Not quite. Try another option.
Answer: Parse the documented log format with a quote-aware parser, then count the status field
Log formats are configurable, and quoted fields can contain spaces. A parser aligned with the configured format preserves field boundaries and avoids mistaking other three-digit values for statuses.
Question 52 of 60 · Access log summarizer · Hard
A summarizer must process access.log plus rotated files ending in .gz as one stream. Which Bash pattern handles filenames safely and decompresses only the compressed files?
Not quite. Try another option.
Answer: for f in access.log access.log.*; do [[ -e $f ]] || continue; case $f in *.gz) gzip -cd -- "$f";; *) cat -- "$f";; esac; done | summarize
The loop preserves filename boundaries, handles an unmatched glob, and chooses decompression by suffix. The other forms mishandle plain files, whitespace, or both.
Question 53 of 60 · Sending emails with SSMTP · Hard
Which message structure is required when piping a complete email to ssmtp recipient@example.com?
Not quite. Try another option.
Answer: RFC-style headers, one blank line, then the message body
A complete message places headers such as From, To, and Subject first. A blank line terminates the headers and begins the body.
Question 54 of 60 · Sending emails with SSMTP · Hard
A backup script uses generate_report | ssmtp admin@example.com, but with default pipeline semantics it can report success when generate_report fails and ssmtp exits successfully. Which setting makes the pipeline fail when either stage fails?
Not quite. Try another option.
Answer: set -o pipefail
Without pipefail, a pipeline normally returns the status of its final command. pipefail propagates a nonzero status from a failed report generator or mail sender.
Question 55 of 60 · Password generator · Hard
A password generator maps each random byte to an alphabet of size using byte % 62. Which method removes modulo bias?
Not quite. Try another option.
Answer: Reject bytes at least , then reduce accepted bytes modulo 62
Since 256 is not divisible by 62, direct modulo mapping favors some symbols. Rejection sampling keeps only a range whose size is an exact multiple of 62.
Question 56 of 60 · Password generator · Hard
A generator runs tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 24 under set -o pipefail. It sometimes reports failure despite producing 24 characters. What is the most likely cause?
Not quite. Try another option.
Answer: head exits after 24 characters, causing upstream tr to receive SIGPIPE
Once head has enough output, it closes the pipe. The still-running tr can terminate on SIGPIPE, and pipefail exposes that nonzero upstream status.
Question 57 of 60 · Pipes versus redirection · Hard
Why does count=0; printf '%s\n' a b | while read -r x; do ((count++)); done; echo "$count" commonly print 0 in Bash, and which rewrite preserves the updates?
Not quite. Try another option.
Answer: The piped loop runs in a subshell; use while read -r x; do ((count++)); done < <(printf '%s\n' a b)
Pipeline components commonly execute in subshells, so their variable changes do not reach the parent shell. Process substitution redirects input while leaving the loop in the current shell.
Question 58 of 60 · Pipes versus redirection · Hard
Which command sends both standard output and standard error to combined.log, replacing the file, and why is redirection order significant?
Not quite. Try another option.
Answer: command > combined.log 2>&1, because standard error duplicates the already redirected standard output
Redirections are processed left to right. Standard output is first attached to the file, then standard error is duplicated from that updated descriptor.
Question 59 of 60 · Automated WordPress setup on LAMP stack · Hard
An automated WordPress installer may be rerun after a partial failure. Which database provisioning approach is most idempotent?
Not quite. Try another option.
Answer: Use CREATE DATABASE IF NOT EXISTS, ensure the user exists, and reapply the required grants
Idempotent provisioning converges existing and new installations toward the desired database, account, and privileges without destroying content or hiding genuine failures.
Question 60 of 60 · Automated WordPress setup on LAMP stack · Hard
A root-run setup script downloads WordPress and executes WP-CLI. Which practice best avoids later ownership and permission failures when WordPress performs updates through the web server account?
Not quite. Try another option.
Answer: Run filesystem-changing WP-CLI commands as the intended site owner and assign narrowly scoped ownership
Using the intended site owner prevents root-owned generated files while avoiding world-writable permissions. Ownership and write access should be limited to directories that require modification.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSC104 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSC104 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.