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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:32:40  来源:igfitidea点击:

How can I concat two strings with tab in bash?

bashechoconcat

提问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 -ewhile echoing the value.

您需要引用变量。此外,由于您已经在分配给 期间解释了转义序列c,因此您无需-e在回显值时指定。