Question 14 of 20Pro Only

How do you write for and while loops in Bash? Can you show examples of iterating over files and command output?

Sample answer preview

Bash provides several loop constructs, each suited for different situations. The for loop iterates over a list of items. The basic syntax uses the in keyword: for file in *.log; do echo "Processing $file" gzip "$file" done You can also iterate over command output using command…

for loopwhile loopuntil loopread commandbrace expansionfind with while

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 19+ more DevOps Engineer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime