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