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