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!
2 Answers
To write a newline use \n not /n the latter is just a slash and a n
Try this:
printf '\n%s\n' '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 %s\n' "$quantity" "$price" "$description" 38 142.15 advanced widget 1