โ† 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 command is used to define a function in Bash?

    Answer: function myfunc() {} or myfunc() {}

    Bash accepts both the function keyword form and the compact name() {} form for defining functions.

  2. What does the `-z` flag test in a Bash conditional?

    Answer: Whether a string is empty (zero length)

    [ -z "$var" ] returns true when the string variable is empty (has zero length).

  3. Given `array=(a b c d)`, what does `${#array[@]}` return?

    Answer: The number of elements (4)

    ${#array[@]} returns the count of elements in the array, which is 4 for this example.

  4. What is a heredoc used for in Bash scripting?

    Answer: Passing a multi-line block of text to a command as stdin

    A heredoc (<<DELIMITER) allows embedding a multi-line string literal directly in a script as standard input to a command.

  5. Which statement correctly breaks out of a loop early in Bash?

    Answer: break

    The break statement terminates the innermost loop and continues execution after it.

  6. In command substitution, what is the difference between backticks and $(...)?

    Answer: $(...) is preferred because it supports nesting and is more readable

    $(...) is the modern preferred form because it can be nested and is easier to read than backticks.

  7. Which variable holds the name of the currently executing Bash script?

    Answer: $0

    $0 contains the name or path of the script (or shell) as it was invoked.