bash 如何在bash中使用制表符连接两个字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18755691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I concat two strings with tab in bash?
提问by android_su
There's a snippet code here.
这里有一个片段代码。
$ a=aa
$ b=bb
$ echo -e $a"\t"$b
aa bb
$ c=`echo -e $a"\t"$b`
$ echo $c
aa bb
$ echo -e $c
aa bb
I wanna concat the $a and $b with tab, and set the result to variable c for a further use.
我想用制表符连接 $a 和 $b,并将结果设置为变量 c 以供进一步使用。
But When I echo $c, no tab display, only a space.
但是当我回显 $c 时,没有标签显示,只有一个空格。
What should I do?
我该怎么办?
回答by sat
Try this:
尝试这个:
echo "$c"
You need to quote the variable. Moreover, since you already interpretedthe escape sequence during the assignment to c
, you don't need to specify -e
while echoing the value.
您需要引用变量。此外,由于您已经在分配给 期间解释了转义序列c
,因此您无需-e
在回显值时指定。