Shell Scripting & Automation Flashcards
7 cards from real LCA practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Shell Scripting & Automation flashcards as text
Which operator is used for arithmetic expansion in bash?
Answer: $(( ))
The `$(( ))` syntax performs arithmetic expansion and is the preferred POSIX-compatible method.
How do you redirect both stdout and stderr to the same file in bash?
Answer: command &> file
`&>` is bash shorthand for redirecting both stdout (fd 1) and stderr (fd 2) to the same destination.
What does `command -v ls` return when `ls` is found in PATH?
Answer: The full path or alias of ls
`command -v` prints the resolved path or alias for a command, making it useful for checking if a command exists.
In a bash script, which syntax correctly passes an array as individual arguments to a function?
Answer: func "${arr[@]}"
`"${arr[@]}"` expands each array element as a separate quoted word, preserving elements with spaces.
What is the purpose of `exec 3>&1` in a bash script?
Answer: Saves the current stdout to file descriptor 3
`exec 3>&1` duplicates stdout to fd 3, allowing you to save and later restore the original stdout.
Which construct in bash is used to perform pattern matching in a case statement?
Answer: case $VAR in pattern) ... ;; esac
The `case ... esac` construct uses glob patterns to match values and execute corresponding code blocks.
What does the `local` keyword do inside a bash function?
Answer: Declares a variable scoped to the function
`local` creates a variable whose scope is limited to the enclosing function and its children.