← Back to Quiz Home
This quiz contains 20 questions focused on Loops, Arrays, Conditionals, and File Operations .
Mastering these concepts is crucial for writing robust automation scripts.
Which loop is best for iterating over a known list of items?
The for loop is designed to iterate over a list of items or a range of numbers.
How do you define an array in Bash?
Bash arrays are defined using parentheses () with space-separated values.
How do you access the first element of an array named arr?
Curly braces {} are required to access array elements by index.
Which command prints all elements of an array?
${arr[@]} (or ${arr[*]}) expands to all elements of the array.
Which loop executes as long as the condition is true?
The while loop continues executing its block as long as the test condition returns true (exit status 0).
Which loop executes as long as the condition is false?
The until loop runs until the condition becomes true (i.e., while it is false).
How do you perform an arithmetic comparison for "equal to" in [ ]?
Inside [ ], -eq is used for integer comparison. == or = is for string comparison.
Which operator checks if a string is empty?
-z returns true if the length of the string is zero.
Which command is used to increment a variable i?
Double parentheses ((...)) allows C-style arithmetic operations, including auto-increment.
How do you iterate through all .txt files in a directory?
Globbing (*.txt) expands to the list of matching filenames, which the for loop iterates over.
What does the continue statement do?
continue skips the remaining commands in the current loop cycle and jumps to the next iteration.
How do you read a file line by line?
Redirecting input < file into a while read loop is the standard, safe way to read lines.
Which logical operator represents "AND" in [[ ]]?
Inside [[ ]] (and for command chaining), && is the logical AND operator.
Which logical operator represents "OR" in [[ ]]?
|| is the logical OR operator.
How do you check if a file is writable?
-w checks if the file exists and is writable by the current user.
How do you calculate the length of an array?
${#arr[@]} expands to the number of elements in the array.
How do you check if a variable VAR is set (not empty)?
-n returns true if the length of the string is non-zero (i.e., it is not empty).
How do you define a range in a for loop?
Brace expansion {1..5} generates the sequence 1 2 3 4 5.
What is the proper syntax for an arithmetic condition?
Double parentheses ((...)) are specifically designed for arithmetic evaluations.
How do you break out of an infinite loop?
break terminates the execution of the loop immediately.
Quiz Progress
0 / 0 questions answered
(0% )
0 correct
Quiz Complete!
0%
Reset quiz
📚 Study Guides
📬 Weekly DevOps, Cloud & Gen AI quizzes & guides