The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 11-16-2008
elbombillo elbombillo is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 48
Quote:
Originally Posted by Christoph Spohr View Post
Hi,

under bash you can try

dns=( $(awk '/nameserver/{print $2}' /etc/resolv.conf ) )

This will give you the second field of all lines matching nameserver read into an array. You can access the data with: echo ${dns[0]}, ${dns[1]} etc.

Kind regards

Chris
Thanks that works but it doesn't like it if the file is empty. I guess I can do my standard grep nameservers | wc -l to check if there is an entry first.