It is an extremely in-efficient way to use printf()
without using format specifiers. You generally define them to let know what type of output is being formatted. It should have been written as
printf '%s\n' "-----------"
Such that the printf
matches the -----------
as a string type with the format specifier that takes a string keyword (%s
). The \n
after the specifier means, add the new line after the string is printed.
With the attempt what you have, when the quote removal happens printf
interprets the dashes as one of its command line flags, which it does not understand.
Another hacky way of doing it would be to let printf
know that its command line arguments are complete and interpret the content following it as its arguments. Most of the shell built-ins and/or external commands support this by suffixing a --
after the command keyword, i.e. as
printf -- "-----------\n"
printf '%s %s %s\n' '---' "$( date )" '---'
? i was guessing it is moreprintf '--- %s ---\n' "$( date )"
like in other shell or C like format of printf – NeronLeVelu Jan 13 '20 at 11:33