Bash: Why is echo adding extra space?

后端 未结 7 1965
轻奢々
轻奢々 2021-01-04 11:15

I get:

$ echo -e \"D\"{a,b,c}\".jpg\\n\"
Da.jpg
 Db.jpg
 Dc.jpg

Note: The extra spaces before Db and Dc on the 2nd and 3rd line of the outp

相关标签:
7条回答
  • 2021-01-04 12:03

    Here is a solution using sed (that builds upon https://stackoverflow.com/a/2003856/8180143):

    $ echo -en "" "D"{a..c}".jpg\n" | sed 's/ //'
    Da.jpg
    Db.jpg
    Dc.jpg
    

    This solution has the advantage of working with inputs having spaces, e.g.,

    $ echo -en "" "D "{a..c}".jpg\n" | sed 's/ //'
    D a.jpg
    D b.jpg
    D c.jpg
    
    0 讨论(0)
提交回复
热议问题