You are writing a Bash script that loops through a list of hosts, calls a scanning utility, and appends the results to a single file. Which approach meets these objectives in a repeatable manner?
Use a for statement that runs the utility on each address, appending the output each time.
Create a function that prompts for each address and merges results in memory for later display.
Call the scanning utility once against all addresses at once, writing results to separate files.
Use a while statement that reads each address, runs the utility, and overwrites the output file with each iteration.
A for statement can iterate over each target, sending the scanner’s output to a single file using the append operator. This method consolidates all results without overwriting existing data. A while statement with overwrite would remove prior output. Calling one scanning utility invocation with multiple addresses may break host-by-host documentation. A prompt-based function loses the streamlined nature of a loop and risks overwriting prior results in memory.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of the Bash append operator in this context?
Open an interactive chat with Bash
Why is a for loop more suitable for iterating over a list of hosts?
Open an interactive chat with Bash
What issues arise if the scanning utility runs against all addresses at once?