“谁"变量中的输出丢失其格式 [英] "whois" output in a variable loses its formatting

查看:123
本文介绍了“谁"变量中的输出丢失其格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览我写的旧脚本,该脚本将whois输出写入文件,然后将grep写入该文件中的某些信息.

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.

我想也许应该更改此设置并将whois输出保存为变量-但是当我这样做时,输出将失去其格式.

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
 [...]

所需的输出:

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

.....

......

如何将whois输出保存到变量而不丢失其格式?

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

推荐答案

这可能是引用问题.代替

This might be a quoting issue. Instead of

echo $info_domain

尝试

echo "$info_domain"

,以便保留格式.从技术上讲,双引号可以防止外壳专家称其为单词拆分.

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

这篇关于“谁"变量中的输出丢失其格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆