1In Bash scripting, which of the following is a valid syntax for defining a function named myFunc?
A.def myFunc():
B.function myFunc { commands; }
C.func myFunc() { commands }
D.myFunc = function() { commands; }
Correct Answer: function myFunc { commands; }
Explanation:Bash functions can be defined using function name { commands; } or name() { commands; }. The def keyword is used in Python, not Bash.
Incorrect! Try again.
2When writing a multi-function script, how do you define a variable that is only accessible within the function it is declared in?
A.private var_name
B.local var_name
C.const var_name
D.restricted var_name
Correct Answer: local var_name
Explanation:The local keyword restricts the scope of a variable to the function in which it is declared, preventing it from overwriting global variables.
Incorrect! Try again.
3Inside a function, how do you access the first argument passed specifically to that function?
A.$ARG1
B.$0
C.$1
D.@{1}
Correct Answer: $1
Explanation:Inside a function, 2, etc., refer to the arguments passed to the function, not the arguments passed to the script. $0 remains the script name.
Incorrect! Try again.
4Which command is used to return a numeric exit status from a function to the caller?
A.back
B.return
C.exit
D.echo
Correct Answer: return
Explanation:return sends an exit status (0-255) back to the caller. exit terminates the entire script, and echo is used to output strings.
Incorrect! Try again.
5To enable an interactive menu, which Bash command is commonly used to accept single-character input without requiring the user to press Enter?
A.read -p
B.read -n 1
C.input -char
D.getch
Correct Answer: read -n 1
Explanation:The -n flag with read allows you to specify the number of characters to accept. read -n 1 accepts one character and immediately proceeds.
Incorrect! Try again.
6Which ANSI escape code sequence is typically used to print text in Red?
A.\033[0;31m
B.\033[0;32m
C.\033[0;34m
D.\color{red}
Correct Answer: \033[0;31m
Explanation:ANSI escape codes start with \033[. 31m indicates red foreground text. 32m is green, and 34m is blue.
Incorrect! Try again.
7When using ANSI escape codes for colors, what is the code \033[0m used for?
A.Set background to black
B.Make text bold
C.Reset/Normalize all attributes
D.Clear the screen
Correct Answer: Reset/Normalize all attributes
Explanation:\033[0m resets all color and formatting attributes to the terminal default.
Incorrect! Try again.
8Which control structure is most efficient for handling multiple choices in an interactive menu script?
A.if-else chain
B.case statement
C.for loop
D.while loop
Correct Answer: case statement
Explanation:The case statement is designed specifically for handling multiple distinct values (patterns) for a single variable, making it ideal for menu selections.
Incorrect! Try again.
9What is the primary command used to securely execute a script on a remote server?
A.telnet
B.ftp
C.ssh
D.netcat
Correct Answer: ssh
Explanation:SSH (Secure Shell) is the standard protocol for secure remote login and command execution.
Incorrect! Try again.
10How can you execute a local script named setup.sh on a remote server user@host without copying the file there first?
A.ssh user@host < setup.sh
B.ssh user@host exec setup.sh
C.scp setup.sh user@host && run
D.ssh user@host -s setup.sh
Correct Answer: ssh user@host < setup.sh
Explanation:By using input redirection (<), the content of the local script is fed into the standard input of the SSH session, executing it remotely.
Incorrect! Try again.
11To perform remote execution without entering a password every time, which mechanism should be set up?
A.SSH Key-based Authentication
B.Telnet plain text
C.Hardcoded password in script
D.Root permission
Correct Answer: SSH Key-based Authentication
Explanation:SSH keys (public/private key pairs) provide a secure way to log in without passwords, enabling automated scripts.
Incorrect! Try again.
12Which command-line tool is specifically designed to parse, filter, and map JSON data in the terminal?
A.awk
B.sed
C.grep
D.jq
Correct Answer: jq
Explanation:jq is a lightweight and flexible command-line JSON processor.
Incorrect! Try again.
13Given the JSON {"status": "active", "id": 50}, which jq filter extracts the value of the status?
A.jq .status
B.jq 'status'
C.jq [status]
D.jq -extract status
Correct Answer: jq .status
Explanation:In jq, the dot operator . followed by the key name retrieves the value associated with that key.
Incorrect! Try again.
14What does the jq command jq '.' do to raw JSON input?
A.Deletes the JSON
B.Minifies the JSON
C.Pretty-prints/Formats the JSON
D.Extracts the first element
Correct Answer: Pretty-prints/Formats the JSON
Explanation:The identity filter . passes the input to the output unchanged but formatted (pretty-printed) with indentation and colors.
Incorrect! Try again.
15Given a JSON array [{"id":1}, {"id":2}], how do you access the first object using jq?
A.jq .array(0)
B.jq .[1]
C.jq .[0]
D.jq .first
Correct Answer: jq .[0]
Explanation:JSON arrays are zero-indexed. .[0] accesses the first element of the array.
Incorrect! Try again.
16When interacting with the Cloudflare API via curl, which HTTP header is used for authentication using an API Token?
Explanation:Modern Cloudflare API interaction uses the standard Bearer token format in the Authorization header.
Incorrect! Try again.
17Which curl flag is used to send JSON data as the payload (body) of a request?
A.-d or --data
B.-j or --json
C.-b or --body
D.-p or --payload
Correct Answer: -d or --data
Explanation:The -d or --data flag is used to send data in a POST or PUT request. You must also usually specify -H "Content-Type: application/json".
Incorrect! Try again.
18If you need to update a DNS record via Cloudflare API, which HTTP method is appropriate?
A.GET
B.PUT
C.HEAD
D.DELETE
Correct Answer: PUT
Explanation:The PUT (or PATCH) method is used to update or replace an existing resource.
Incorrect! Try again.
19In an Apache access log, which command is most suitable for extracting just the IP addresses (usually the first column)?
A.awk '{print $1}'
B.grep '$1'
C.cut -c 1-5
D.sed 'delete all'
Correct Answer: awk '{print $1}'
Explanation:awk splits lines by whitespace by default. '{print $1}' outputs the first field, which is the IP address in standard log formats.
Incorrect! Try again.
20When summarizing logs, what does the command sequence sort | uniq -c do?
A.Sorts lines and removes duplicates
B.Sorts lines and counts the occurrences of each unique line
C.Sorts lines and deletes unique lines
D.Uniquely sorts characters
Correct Answer: Sorts lines and counts the occurrences of each unique line
Explanation:sort groups identical lines together. uniq -c filters adjacent matching lines and prefixes them with the count of occurrences.
Incorrect! Try again.
21Which command would you use to filter an access log for only entries resulting in a '404 Not Found' error?
A.grep "404"
B.find "404"
C.locate "404"
D.cat "404"
Correct Answer: grep "404"
Explanation:grep is the standard utility for searching plain-text data sets for lines that match a regular expression or string.
Incorrect! Try again.
22What is the primary function of SSMTP in a scripting context?
A.To receive emails (IMAP server)
B.To act as a full-featured mail server like Exchange
C.To send emails from the command line via an external SMTP server
D.To encrypt emails using PGP
Correct Answer: To send emails from the command line via an external SMTP server
Explanation:SSMTP is a simple MTA (Mail Transfer Agent) to deliver mail from a local computer to a configured mailhub (SMTP server).
Incorrect! Try again.
23Which configuration file typically holds the credentials and server details for SSMTP?
A./etc/ssh/sshd_config
B./etc/ssmtp/ssmtp.conf
C./var/www/html/config.php
D./etc/mail/sendmail.cf
Correct Answer: /etc/ssmtp/ssmtp.conf
Explanation:The main configuration file for SSMTP is located at /etc/ssmtp/ssmtp.conf.
Incorrect! Try again.
24To generate a random password, which system file serves as a source of non-blocking pseudorandom data?
A./dev/null
B./dev/zero
C./dev/urandom
D./dev/randomness
Correct Answer: /dev/urandom
Explanation:urandom (unlimited random) provides a source of random data suitable for most cryptographic uses without blocking for entropy accumulation.
Incorrect! Try again.
25In a password generator script, what does tr -dc 'A-Za-z0-9' do?
A.Translates lower case to upper case
B.Deletes all characters except the complement (alphanumeric)
C.Deletes alphanumeric characters
D.Encrypts the input
Correct Answer: Deletes all characters except the complement (alphanumeric)
Explanation:tr is translate/delete. -d deletes, -c takes the complement. Together, they keep only the characters defined in the set 'A-Za-z0-9'.
Incorrect! Try again.
26Which command allows you to cut a stream of characters to a specific length (e.g., take the first 12 characters)?
A.tail -c 12
B.head -c 12
C.cut -d 12
D.grep -12
Correct Answer: head -c 12
Explanation:head outputs the first part of files. The -c 12 flag tells it to output the first 12 bytes/characters.
Incorrect! Try again.
27What is the fundamental difference between a pipe | and redirection >?
A.| sends output to a file; > sends output to a command
B.| sends output to another command; > sends output to a file
C.There is no difference
D.> is used for errors only
Correct Answer: | sends output to another command; > sends output to a file
Explanation:Pipes pass stdout of one process to stdin of another process. Redirection > writes stdout to a file on the disk.
Incorrect! Try again.
28If you use >> instead of > when redirecting output to a file, what happens?
A.The file is overwritten
B.The file is deleted
C.The output is appended to the end of the file
D.The command fails if the file exists
Correct Answer: The output is appended to the end of the file
Explanation:>> appends data to the file, preserving existing content, whereas > overwrites the file.
Incorrect! Try again.
29How do you redirect Standard Error (stderr) to a file?
A.1>
B.2>
C.&>
D.|>
Correct Answer: 2>
Explanation:File descriptor 1 is stdout, and 2 is stderr. 2> redirects error messages to a file.
Incorrect! Try again.
30In the context of automating WordPress setup, what is the purpose of wget https://wordpress.org/latest.tar.gz?
A.To install Apache
B.To download the WordPress source files
C.To configure the database
D.To update the OS
Correct Answer: To download the WordPress source files
Explanation:wget is a utility for non-interactive download of files from the web. This command downloads the latest WordPress archive.
Incorrect! Try again.
31Which command is used to extract the .tar.gz file downloaded for WordPress?
A.unzip latest.tar.gz
B.tar -xzf latest.tar.gz
C.rar x latest.tar.gz
D.gunzip latest.tar.gz
Correct Answer: tar -xzf latest.tar.gz
Explanation:tar is the archive utility. -x extracts, -z handles gzip compression, and -f specifies the filename.
Incorrect! Try again.
32In a LAMP stack automation script, which user usually owns the web directory (/var/www/html) for security and write access?
A.root
B.admin
C.www-data
D.guest
Correct Answer: www-data
Explanation:On Ubuntu/Debian systems, www-data is the default user and group under which the Apache web server runs.
Incorrect! Try again.
33When automating the database setup for WordPress, which SQL command creates the database?
A.MAKE DATABASE wordpress;
B.CREATE DATABASE wordpress;
C.NEW DATABASE wordpress;
D.INIT DATABASE wordpress;
Correct Answer: CREATE DATABASE wordpress;
Explanation:Standard SQL syntax for creating a new database is CREATE DATABASE dbname;.
Incorrect! Try again.
34To allow WordPress to connect to the database, which file needs to be created from wp-config-sample.php?
A.wp-settings.php
B.wp-connect.php
C.wp-config.php
D.config.php
Correct Answer: wp-config.php
Explanation:WordPress looks for wp-config.php for database connection details. It is usually created by copying the sample file and modifying it.
Incorrect! Try again.
35Which sed command pattern is best for replacing a placeholder like database_name_here in a config file?
A.sed -i 's/database_name_here/my_db/' file
B.sed -r 'database_name_here -> my_db' file
C.sed 'delete database_name_here' file
D.sed -x 'my_db' file
Correct Answer: sed -i 's/database_name_here/my_db/' file
Explanation:sed -i edits the file in place. The s/old/new/ syntax is the standard substitution command.
Incorrect! Try again.
36What is the result of the logical operation cmd1 && cmd2 in a script?
A.cmd2 runs only if cmd1 succeeds
B.cmd2 runs only if cmd1 fails
C.Both commands run simultaneously
D.cmd1 runs only if cmd2 succeeds
Correct Answer: cmd2 runs only if cmd1 succeeds
Explanation:The && operator is a logical AND. The second command executes only if the first command returns an exit status of 0 (success).
Incorrect! Try again.
37When using curl to fetch JSON data, how do you suppress the progress meter output?
A.-v
B.-s
C.--verbose
D.-P
Correct Answer: -s
Explanation:The -s or --silent flag tells curl not to show the progress meter or error messages.
Incorrect! Try again.
38In a bash script, what does set -e do?
A.Enables syntax highlighting
B.Exports all variables
C.Exits the script immediately if a command exits with a non-zero status
D.Enables debugging mode
Correct Answer: Exits the script immediately if a command exits with a non-zero status
Explanation:set -e causes the shell to exit immediately if any command (not part of a condition) fails, which is useful for error handling in automation scripts.
Incorrect! Try again.
39Which tool would you use to verify that a variable $JSON contains valid JSON syntax before parsing it?
A.echo "$JSON" | jq .
B.echo "$JSON" | grep json
C.cat "$JSON"
D.validate_json "$JSON"
Correct Answer: echo "$JSON" | jq .
Explanation:Piping content to jq . is a common way to validate JSON. If it is invalid, jq will return an error status.
Incorrect! Try again.
40When creating a log summarizer, which awk variable represents the number of fields (columns) in the current line?
A.NR
B.NF
C.FS
D.$$
Correct Answer: NF
Explanation:NF (Number of Fields) holds the count of fields in the current record.
Incorrect! Try again.
41In an interactive menu, how do you create an infinite loop that keeps the menu open until the user chooses to exit?
A.for i in {1..100}; do ... done
B.while true; do ... done
C.until false; do ... done
D.repeat ... until exit
Correct Answer: while true; do ... done
Explanation:while true creates an infinite loop because the condition true always returns exit status 0.
Incorrect! Try again.
42How do you securely supply a password to mysql in a script without the prompt interrupting the automation?
A.mysql -u user -pPASSWORD
B.It is impossible
C.Type it manually
D.Use telnet
Correct Answer: mysql -u user -pPASSWORD
Explanation:While storing passwords in scripts is a security risk, mechanically, supplying -p immediately followed by the password (no space) automates the login.
Incorrect! Try again.
43What is the purpose of ssh-copy-id user@host?
A.To copy the SSH daemon to a remote server
B.To copy your public key to the remote server's authorized_keys
C.To copy files securely
D.To duplicate the server ID
Correct Answer: To copy your public key to the remote server's authorized_keys
Explanation:ssh-copy-id is a script that installs your public key in the remote machine's ~/.ssh/authorized_keys file to enable key-based auth.
Incorrect! Try again.
44When using grep, which flag allows you to search using Extended Regular Expressions (like | for OR)?
A.-i
B.-E
C.-v
D.-x
Correct Answer: -E
Explanation:grep -E (equivalent to egrep) interprets patterns as extended regular expressions.
Incorrect! Try again.
45In an SSMTP email body, what must usually be the first line to ensure the recipient is displayed correctly in email clients?
A.Subject: My Subject
B.To: recipient@example.com
C.From: me@example.com
D.Hello World
Correct Answer: To: recipient@example.com
Explanation:While ssmtp takes the recipient as an argument, the actual email content (headers) must start with To: ..., followed by From:, Subject:, and a blank line before the body.
Incorrect! Try again.
46Which of the following generates a random 16-character string using openssl?
A.openssl rand -base64 12
B.openssl genrsa 16
C.openssl sha256
D.openssl random 16
Correct Answer: openssl rand -base64 12
Explanation:openssl rand -base64 12 generates random bytes and encodes them in base64. 12 bytes in base64 results in approx 16 printed characters.
Incorrect! Try again.
47If you want to debug a script by printing every command before it is executed, how do you run the script?
A.bash -x script.sh
B.bash -d script.sh
C.bash -v script.sh
D.bash -e script.sh
Correct Answer: bash -x script.sh
Explanation:The -x (xtrace) option prints commands and their arguments as they are executed.
Incorrect! Try again.
48When automating the Apache service, which command ensures Apache starts automatically when the server boots?
A.systemctl start apache2
B.systemctl enable apache2
C.service apache2 run
D.apache2 --init
Correct Answer: systemctl enable apache2
Explanation:systemctl enable creates the necessary symbolic links to start the service at boot time.
Incorrect! Try again.
49Which mathematical operator in a Bash arithmetic expansion a ? $b)) performs the modulo operation?
A./
B.%
C.*
D.#
Correct Answer: %
Explanation:The % symbol is used for the modulo operation (remainder) in Bash arithmetic. E.g., a % $b)).
Incorrect! Try again.
50In a JSON API response, if a key contains a special character (e.g., user-name), how must it be referenced in jq?
A..user-name
B.."user-name"
C..['user-name']
D.Both B and C
Correct Answer: Both B and C
Explanation:If a key contains special characters like hyphens, it must be quoted: ."key-name". You can also use the bracket notation ["key-name"]. Using .user-name would be interpreted as subtraction.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.