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 Bash test expression correctly checks if a file exists AND is readable?
Answer: [[ -e file && -r file ]]
[[ -e file && -r file ]] uses the modern double-bracket syntax with && to combine both existence and readability tests.
What does the trap command accomplish in a Bash script?
Answer: Registers a handler to execute when a signal or event occurs
trap associates a command or function with a signal (like INT or EXIT) so cleanup code runs on termination.
In Bash arithmetic, which syntax evaluates an integer expression and returns its value?
Answer: $(( expr ))
$(( expr )) is the POSIX-compliant arithmetic expansion syntax for integer math in Bash.
Which getopts usage correctly parses a script option '-f' that requires an argument?
Answer: getopts 'f:' opt
A colon after the option letter in the optstring tells getopts that the option requires an argument, stored in $OPTARG.
What is the output of: echo ${#myvar} when myvar='hello'?
Answer: 5
${#varname} is the Bash parameter expansion that returns the length of the variable's string value.
Which command creates a named pipe (FIFO) in Linux?
Answer: mkfifo
mkfifo creates a named pipe (FIFO special file) that allows inter-process communication via the filesystem.
A script uses 'exec 3< inputfile'. What does file descriptor 3 now represent?
Answer: A read-only file descriptor open on inputfile
exec 3< inputfile opens inputfile for reading on file descriptor 3, allowing the script to read from it independently of stdin.