How do I add a new line to a print command using printf?
printf "I want this on a new line!"
I thought it would be something like this but it didn't work
printf "/n I want this on a new line!/n"
Thanks in advance for the help!
The printf statement does not automatically append a newline to its output. It outputs only what the format string specifies. So if a newline is needed, you must include one in the format string. The output separator variables OFS and ORS have no effect on printf statements.
The sequence \" translates as a literal double-quote; it is escaped with a backslash so that printf knows to treat it as a literal character, and not as the end of the FORMAT string. \n is the sequence for a newline character, and tells printf to begin a new line and continue the output from there.
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
To write a newline use \n
not /n
the latter is just a slash and a n
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With