โ† All 010-160 Flashcard Decks

Basic Scripting Concepts Flashcards

7 cards from real 010-160 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Basic Scripting Concepts flashcards as text
  1. Which shell built-in command is used to read a line of input from the user and store it in a variable?

    Answer: read

    The `read` built-in reads a line from standard input and assigns it to the named variable.

  2. What does the following condition test in a bash `if` statement: `[ -f /etc/hosts ]`?

    Answer: Whether /etc/hosts exists and is a regular file

    The `-f` file test operator returns true when the path exists and is a regular file.

  3. In bash, what is the value of `$?` after a command exits successfully?

    Answer: 0

    `$?` holds the exit status of the last command; 0 conventionally means success.

  4. Which of the following correctly defines a shell function named `greet`?

    Answer: greet() { echo Hello; }

    The POSIX-compatible syntax `name() { commands; }` defines a shell function.

  5. What arithmetic value does `$(( 3 ** 2 ))` evaluate to in bash?

    Answer: 9

    The `**` operator performs exponentiation, so 3 to the power of 2 equals 9.

  6. Which command would you use inside a script to terminate with exit code 2?

    Answer: exit 2

    The `exit` command ends the script and passes its numeric argument as the exit status.

  7. What does a `#!` (shebang) line at the top of a script specify?

    Answer: The interpreter used to execute the script

    The shebang (`#!`) followed by a path tells the kernel which interpreter to use to run the script.