问题
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