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
Which construct is used to iterate over each line of a file in a Bash script?
Answer: while IFS= read -r line; do ... done < file.txt
The while read loop with input redirection (<) is the correct and safe idiom for reading files line by line in Bash.
What does the special variable $? represent in a Bash script?
Answer: The exit status of the last executed command
$? holds the exit status (return code) of the most recently executed foreground command, where 0 means success.
Which Bash operator sends standard error to the same destination as standard output?
Answer: 2>&1
2>&1 redirects file descriptor 2 (stderr) to wherever file descriptor 1 (stdout) is currently pointing.
In a Bash case statement, what symbol marks the end of each pattern block?
Answer: ;;
Each case pattern block is terminated with ;; which causes Bash to skip to the esac keyword.
What is the purpose of the 'local' keyword inside a Bash function?
Answer: It declares a variable scoped only to that function
Variables declared with 'local' exist only within the function scope and do not pollute the global environment.
Which command substitution syntax is preferred in modern Bash scripts over backticks?
Answer: $(cmd)
$(cmd) is the preferred modern form because it nests cleanly and is more readable than backticks.
What does 'set -e' do at the top of a Bash script?
Answer: Causes the script to exit immediately on any command error
set -e (errexit) makes the script terminate as soon as any command returns a non-zero exit code.