Confusion with printf command?

% is a special character in printf. That's what's causing the error. You need to escape it as %%.

$ may also be substituted when within double quotes by the outer shell, so you should to escape that (\$). It is usually just easier to use single quotes.


Better to use:

printf "Different characters can be represented and supported\n\
in the print command, for example:\n\
x-y, X+Y, –, +, <, >, %%, $, #, &.\n"

You get that error, as others have said here, because of % character which is special and must to be escaped.

See man 1 printf for more info.


the % is special for printf: it is the leading char in format specifiers. If you want a literal percent, use %%