击:为什么回声增加额外的空间? [英] Bash: Why is echo adding extra space?
问题描述
我得到:
$ echo -e "D"{a,b,c}".jpg\n"
Da.jpg
Db.jpg
Dc.jpg
注:DB和直流之前多余的空格在输出的第二和第三个行
Note: The extra spaces before Db and Dc on the 2nd and 3rd line of the output.
为什么这些呢?
谢谢,
丹
修改:由于我的实际目标有它的空间(这是我应该最初写):
Edit: Since my actual objective had spaces in it (which I should have written originally):
echo -e "Name"{,.}" "{-,}"extra"{,so}" 5v5 "{one,two,No\ four}{,!,\!\!}"\n"
大多数解决方案在这里并没有为我工作(for循环,xarg,TR)。 printf的没有,因为我想cantesian产品多花括号扩展的工作。
Most solutions here didn't work for me (for loop, xarg, tr). Printf didn't work because of multiple braces expansions that I want to cantesian product.
我结合3方案(mletterle的\\ B,丹尼斯·威廉姆森的额外空间,而吉姆丹尼斯的使用远不如引号),以获得:
I combined 3 solutions (mletterle's \b, Dennis Williamson's extra space, and Jim Dennis's using far less quotes) to get:
echo -e "" \\bName{,.}\ {-,}extra{,so}\ 5v5\ {one,two,No\ four}{,\!,\!\!}\\n
感谢所有谁回答!我学到了很多东西,从你的回答!
Thanks all who answered! I learned a lot from your responses!
丹
推荐答案
最简单和干净的解决方案是一个退格添加到每一行的前面:
The easiest and cleanest solution is to add a backspace to the front of each line:
echo -e -n "\bD"{a,b,c}".jpg\n"
这将产生所需的输出。
This produces the desired output.
这篇关于击:为什么回声增加额外的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!