“whois” output in a variable loses its formatting

故事扮演 提交于 2019-12-02 12:19:48

问题


I have been looking through an old script I wrote which writes whois output to a file and then grep for certain info in that file.

I thought maybe I should change this and save the whois output as a variable - but when I do that, the output loses its formatting.

me@server:~$ echo $info_domain
 Whois Server Version 2.0 Domain names in the .com and .net domains
 can now be registered with many different
 competing registrars. Go to http://www.internic.net for detailed
 information. Server Name: EXAMPLE.COM.AU Registrar: ENETICA PTY LTD
 Whois Server: whois.enetica.com.au Referral URL:
 http://www.enetica.com.au Server Name: EXAMPLE.COM.FLORAMEIYUKWONG.COM
 IP Address: 173.203.204.123 Registrar: GODADDY.COM, LLC Whois Server:
 whois.godaddy.com Referral URL: http://registrar.godaddy.com Server
 Name: EXAMPLE.COM.RAFAELYALUFF.COM IP Address: 173.203.204.123
 [...]

Desired Output:

me@server:~$ whois example.com

Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered with many different
competing registrars. Go to http://www.internic.net for detailed information.

   Server Name: EXAMPLE.COM.AU    Registrar: ENETICA PTY LTD    Whois Server: whois.enetica.com.au    Referral URL: http://www.enetica.com.au

   Server Name: EXAMPLE.COM.FLORAMEIYUKWONG.COM    IP Address:
173.203.204.123    Registrar: GODADDY.COM, LLC    Whois Server: whois.godaddy.com    Referral URL: http://registrar.godaddy.com

   Server Name: EXAMPLE.COM.RAFAELYALUFF.COM    IP Address:
173.203.204.123    Registrar: EXAMPLE.COM, LLC    Whois Server: whois.domain.com    Referral URL: http://www.example.com

.....

......

How can I save whois output to a variable without it losing its formatting?


回答1:


This might be a quoting issue. Instead of

echo $info_domain

try

echo "$info_domain"

so that the format is preserved. Technically, the double quotes prevent what shell gurus call word splitting.



来源:https://stackoverflow.com/questions/26177397/whois-output-in-a-variable-loses-its-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!