Printf example in bash does not create a newline

前端 未结 8 1673
臣服心动
臣服心动 2020-12-09 08:20

Working with printf in a bash script, adding no spaces after \"\\n\" does not create a newline, whereas adding a space creates a newline, e. g.:

8条回答
  •  离开以前
    2020-12-09 08:37

    It looks like BASH is removing trailing newlines. e.g.

    NewLine=`printf " \n\n\n"`
    echo -e "Firstline${NewLine}Lastline"
    Firstline Lastline
    
    NewLine=`printf " \n\n\n "`
    echo -e "Firstline${NewLine}Lastline"
    Firstline
    
    
     Lastline
    

提交回复
热议问题