我一直在查看我编写的旧脚本,该脚本将whois输出写入文件,然后grep查找该文件中的某些信息。
我想也许我应该改变这个并将whois作为变量保存 - 但是当我这样做时,whois会丢失它的格式。
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
[...]
期望的输出:
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: DOMAIN.COM, LLC Whois Server: whois.domain.com Referral URL: http://www.domain.com
.....
......
我不知道如何在不丢失格式的情况下将whois保存到变量中。任何帮助都会很棒。
谢谢
答案 0 :(得分:2)
这可能是一个引用问题。而不是
echo $info_domain
试
echo "$info_domain"
以便保留格式。从技术上讲,双引号可以防止shell大师调用分词。