โ† All LCA Flashcard Decks

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
  1. Which operator is used for arithmetic expansion in bash?

    Answer: $(( ))

    The `$(( ))` syntax performs arithmetic expansion and is the preferred POSIX-compatible method.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.