Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create a shell script which receives a vector argument like


and display ip for each domain




while [ "$1" ]; 
host $1 | grep address | head -1
share|improve this question
up vote 5 down vote accepted

You can use the following script:


for domain in $@; do
    host $domain | grep "has address" | awk '{print $1"\t"$4}'

Usage: ./script ...

For example:

$ ./
share|improve this answer
I've edit my question. Please let me know what do you think. – Adrian George Sep 15 '13 at 13:05

You can perform multiple-query lookups directly using the dig command e.g.


or for less verbose output

dig +noall +answer

or to output just the IPs

dig +short
share|improve this answer

You can do that this way.

Open a Terminal

$ gedit &

Add the following lines into the file and Save.


read -p "Enter domain name : " DOMAIN_INPUT



Flag the script as executable

$ chmod +x


neo@neo-H87H3-M:~$ ./

Enter domain name : has address has address has address has address has address has address has IPv6 address 2404:6800:4008:c00::8a mail is handled by 50 mail is handled by 20 mail is handled by 30 mail is handled by 10 mail is handled by 40


share|improve this answer
for multiple domains ? how can I do this ? – Adrian George Sep 14 '13 at 7:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.