You can have as many commands as you like between the "do" and "done", and of course, they can be new loops with "do" and "done" in them. Not sure where you'd need that, though. You can simply modify the sed script to shuffle things around in a different order if that's how you like them.
The "s/from/to/" command in sed will substitute the stuff in "from" with the stuff in "to" on each line. In this case we are replacing the IP address printed by dig with the longer string. & retrieves the "from" string into the "to" string. Dot star is the regular expression for "everything on this line" (dot means any character, star means any number of times).
Just to show an alternate way of doing it, here's a loop which prints the message piecemeal.
Or you can interpolate with backticks
Backticks AKA grave accents (ASCII 96) capture the output of one command so you can use it in the command line of another command. Notice that those are not regular single quotes. Copy/paste them if you can't find them on your keyboard.
Last edited by era; 08-23-2008 at 09:57 PM..
Reason: Show alternate way of coding it with echos to print the desired message
And here's the answer I wanted with desired output:
host -t ns example.com | while read dom ns server; do dig +short $dom | echo $server "shows an IP of" `dig +short $dom` for $dom; done <enter>
Gives me this output:
server a.iana-servers.net. shows an IP of 208.77.188.166 for example.com
server b.iana-servers.net. shows an IP of 208.77.188.166 for example.com