bash IP取得

$ dig +short example.com
93.184.216.34

$ host -t A example.com | awk '/has address/{print $4}'
93.184.216.34

dig コマンドの代わりに host コマンドでIPを取得

#!/bin/bash
server_name="example.com"
ip_addresses=$(host -t A $server_name | awk '/has address/{print $4}')
echo "$server_name IPs: $ip_addresses"

最初のひとつ

#!/bin/bash
server_name="example.com"
ip_address=$(host -t A $server_name | awk '/has address/{print $4}' | head -n 1)
echo "$server_name IP: $ip_address"