You have a script that loops through a list of subdomains to check which ones resolve. The script runs a command on each item and prints lines containing “has address” when an address is found. You want to modify the script so that whenever a line contains “has address,” the resolved address is written to a file named addresses.txt. Which change meets these goals?
Use a command that searches for 'host info' instead of 'has address' and prints to standard output
Modify the file name in the script to addresses.txt and keep the existing command logic
Pipe the output to tail, then append the last line to addresses.txt
Add an if condition that checks for 'has address', then use echo to append the match to addresses.txt
The answer that uses an if statement to check for the text 'has address' and then writes the result to addresses.txt is correct. It ensures that the output is filtered in a conditional block, extracting only lines with an address and storing them for further review. Options that merely print output to the screen or rely on the presence of a different keyword do not fulfill the stated requirement of writing the data to addresses.txt. A statement that checks for a different text pattern will not capture the correct lines.
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 using the 'if' condition in the script?
Open an interactive chat with Bash
Why is appending the output with 'echo' necessary?
Open an interactive chat with Bash
What does 'has address' signify in the script output?