Dashes in printf
The --
is used to tell the program that whatever follows should not be interpreted as a command line option to printf
.
Thus the printf "--"
you tried basically ended up as "printf
with no arguments" and therefore failed.
--
is being interpreted as an option (in this case, to signify that there are no more options).
A format string should always be included when using printf
to prevent bad interpretation. For your particular case:
printf '%s\n' '-----------------------'
There are differences between printf builtin and /usr/bin/printf, the second one do "what you mean" without these annoying errors.
printf "-----" # error
printf -- "-----" # ok
/usr/bin/printf "-----" # ok
/usr/bin/printf -- "-----" # ok