Linux+ Bash Scripting and Automation Flashcards
7 cards from real Linux practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Linux+ Bash Scripting and Automation flashcards as text
What does the Bash option 'set -u' enforce in a script?
Answer: Treats unset variables as errors when expanded
set -u (nounset) causes Bash to exit with an error if any unset variable is referenced, preventing silent bugs from typos.
Which Bash syntax performs string substitution, replacing the FIRST occurrence of 'foo' with 'bar' in variable $str?
Answer: ${str/foo/bar}
${var/pattern/replacement} replaces only the first match, while // would replace all occurrences.
In a Bash script, what does '> /dev/null 2>&1' accomplish when appended to a command?
Answer: Discards both stdout and stderr completely
stdout is redirected to /dev/null (discarded), then stderr is merged into stdout (also /dev/null), silencing all output.
Which command allows you to run a Bash script in debug mode, printing each command before execution?
Answer: bash -x script.sh
bash -x enables xtrace mode, prefixing each executed command with a + sign so you can trace script execution.
What is the effect of using double quotes around a variable in Bash (e.g., "$var")?
Answer: Allows variable expansion but prevents word splitting and globbing
Double quotes preserve whitespace and special characters in a variable's value while still allowing $ expansion.
In Bash, what does the 'read -a arr' command do?
Answer: Reads a line of input and splits it into array arr
read -a reads a line of input and stores each whitespace-delimited word as an element of the named array.
Which cron field order is correct for a crontab entry?
Answer: minute hour day month weekday
A crontab line follows the order: minute (0-59), hour (0-23), day of month, month, day of week, then the command.