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.
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
doesn't have this issue:
$ printf "%s\n" -n
-n
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments