โ† All Linux Flashcard Decks

Linux+ Basic Bash Scripting 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+ Basic Bash Scripting flashcards as text
  1. Which operator is used to append output to an existing file in Bash?

    Answer: >>

    The >> operator appends output to a file without overwriting its existing contents.

  2. What does the special variable $? represent in Bash?

    Answer: The exit status of the last command

    $? holds the exit status of the most recently executed command, where 0 typically means success.

  3. Given the script: `for i in {1..5}; do echo $i; done`, what is the output?

    Answer: Prints 1 through 5 each on a new line

    Brace expansion {1..5} generates the sequence 1 2 3 4 5, so the loop prints each number on its own line.

  4. Which command inside a Bash function returns a value to the caller?

    Answer: return

    The return statement exits a function and sets its exit status code, which the caller can read via $?.

  5. What is the purpose of the `read` command in a Bash script?

    Answer: Reads a line of input from stdin into a variable

    The read command pauses execution and stores a line of user input (or piped input) into one or more variables.

  6. In Bash, what does `[ -d /etc ]` test?

    Answer: Whether /etc exists and is a directory

    The -d flag in a test expression returns true if the given path exists and is a directory.

  7. Which shebang line correctly specifies Bash as the interpreter for a script?

    Answer: #!/usr/bin/env bash

    #!/usr/bin/env bash is the portable shebang that finds bash via the PATH, recommended over hardcoded paths.