奇怪的回声输出 [英] strange echo output

查看:96
本文介绍了奇怪的回声输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下bash shell的这种行为吗?

Can anybody explain this behaviour of the bash shell which is driving me nuts

[root@ns1 bin]# export test=`whois -h whois.lacnic.net 187.14.6.108 | grep -i inetnum: | awk '{print $2}'`

[root@ns1 bin]# echo $test
187.12/14

[root@ns1 bin]# echo "iptables -I INPUT -s $test -J DROP"

-J DROP -I INPUT -s 187.12/14

[root@ns1 bin]# 

为什么我的 echo 搞砸了? $ test 的内容正在更改它。

Why is my echo screwed up? It is being changed by the contents of $test.

如果更改 $ test 转到 ABC就可以了。

If you change $test to "ABC" all is fine. Is it related to the slash?

推荐答案


为什么我的 echo 搞砸了?
$ test 的内容对其进行了更改。

Why is my echo screwed up? It is being changed by the contents of $test.

因为您的测试包含回车符。删除它:

Because your test contains a carriage return. Remove it:

test=$(whois -h whois.lacnic.net 187.14.6.108 | grep -i inetnum: | awk '{print $2}' | tr -d '\r')

这篇关于奇怪的回声输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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