Printf example in bash does not create a newline

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

    For people coming here wondering how to use newlines in arguments to printf, use %b instead of %s:

    $> printf "a%sa" "\n"
    a\na
    $> printf "a%ba" "\n"
    a
    a
    

    From the manual:

    %b expand backslash escape sequences in the corresponding argument

提交回复
热议问题