How can I print "-n" with `echo`?

Michael

I can't figure how to print the string "-n" with the over 30 years-old command echo.

I tried these:

Michaels:Scripts$ echo -n
Michaels:Scripts$ echo "-n"
Michaels:Scripts$ echo -e "-n"
Michaels:Scripts$ echo -- -n
-- -n
Michaels:Script$ echo -- "-n"
-- -n
Michaels:Script$ echo "\-n"
\-n

I use Mac OS X ML. I consider this behaviour very weird and unexpected.

slm

If you don't want to use prinf you have a couple of of options, at least according to this SO Q&A, titled: echo “-n” will not print -n?.

This seems to be your best option:

$ echo "x-n" | cut -c 2-
-n

Or some variation:

$ echo -- '-n'|cut -d" " -f2
-n

printf

printf doesn't have this issue:

$ printf "%s\n" -n
-n

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I check if my function print/echo's something?

From Dev

how i can print some array in echo string

From Dev

How can I print a newline as \n in bash?

From Dev

How can I print a newline as \n in bash?

From Dev

How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

From Dev

How do I print the result of a command with 'echo'?

From Dev

How do I print '-e' with echo?

From Dev

How can i print modal form (popup window) with php echo function?

From Dev

how can i print/echo array keys and values contain in stdClass object and send the values to my mail?

From Dev

How can I print this?

From Dev

How can I print out all but the last n characters in bash?

From Dev

How can I make a echo in echo in laravel with curly braces?

From Java

How can I echo a newline in a batch file?

From Dev

How can i echo string + command in terminal

From Dev

How can I echo dollar signs?

From Dev

How can i order the output of "echo" command

From Dev

How can I echo with escaped spaces?

From Dev

How I can hide this php echo?

From Dev

How do I print/echo out specific array php

From Dev

How to I get ruby `print` to echo to calling bash script?

From Dev

How can I print a Maybe?

From Dev

How can I print 413284921265094656?

From Dev

How can I print 413284921265094656?

From Dev

How can you echo a literal '-n' or '-e'?

From Java

How to print / echo environment variables?

From Dev

How to only print the ID of this echo?

From Dev

how to echo/print block by block

From Dev

How to print 2 echo in li

From Dev

Unable to use an environment variable in command prompt, even though I can print it's value using echo command

Related Related

HotTag

Archive