Printf example in bash does not create a newline

前端 未结 8 1672
臣服心动
臣服心动 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

    Works ok if you add "\r"

    $ nl=`printf "\n\r"` && echo "1${nl}2"
    1
    2
    
    0 讨论(0)
  • 2020-12-09 08:48
    $ printf -v NewLine "\n"
    $ echo -e "Firstline${NewLine}Lastline"
    
    Firstline
    Lastline
    
    $ echo "Firstline${NewLine}Lastline"
    Firstline
    Lastline
    
    0 讨论(0)
提交回复
热议问题