4
printf "-Xdebug"

Gives:

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

echo -n "-Xdebug" works but according to this question here it isn't portable.

There are multiple versions of the echo command, with different behaviors. Apparently the shell used for your script uses a version that doesn't recognize -n.

How can I have a string be printed to screen uninterpreted, as is?

2 Answers 2

10

Add a format string

printf '%s' '-Xdebug'

Or use -- to signal end of option processing

printf -- '-Xdebug'
1
  • 4
    The %s solution is much safer in general — printf -- string will mangle strings that contain % or \. Commented Jun 19, 2015 at 4:44
-2
echo '-Xdebug' > /dev/lpr

It will send the text -Xdebug to the line printer, your default printer. An alternative would be to format it first, with the program fmt:

echo '-Xdebug' | fmt > /dev/lpr
1
  • 1
    'Print' just means display on the screen in this context. The problem is about trying to use printf when the text to print starts with a minus, which is being treated as an option instead of text.
    – Mikel
    Commented Jun 19, 2015 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .