bash – How do I add a newline using printf?

bash – How do I add a newline using printf?

To write a newline use n not /n the latter is just a slash and a n

Try this:

printf n%sn I want this on a new line!

That allows you to separate the formatting from the actual text. You can use multiple placeholders and multiple arguments.

quantity=38; price=142.15; description=advanced widget
$ printf %8d%10.2f  %sn $quantity $price $description
      38    142.15  advanced widget

bash – How do I add a newline using printf?

Leave a Reply

Your email address will not be published.