This question already has an answer here:

how can I use printf to print a row of minus symbols?

when I try: printf "-----------\\n"

I get:

bash: printf: - : invalid option
printf: usage: printf [-v var] format [arguments]

when I try: printf "\-\-\-\-\-\-\-\-\-\-\-\\n"

I get: \-\-\-\-\-\-\-\-\-\-\-

marked as duplicate by A.B, icarus, mosvy, Inian, elbarna Dec 26 '18 at 21:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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"

Not the answer you're looking for? Browse other questions tagged or ask your own question.