This question already has an answer here:
- 'echo' without newline in a shell script 4 answers
Why doesn't $echo '-n'
write -n
on terminal although -n
is written within single quotes ?
This question already has an answer here:
Why doesn't $echo '-n'
write -n
on terminal although -n
is written within single quotes ?
I found that the following just works in bash:
So, you should put -n the first place.
Not quiete there:
surprisingly this works:
and here a solution I can explain:
The quotes don't help because ... ugh, it's hard to explain. The shell strips the quotes off before the "echo" command itself is evaluated, so by that time they don't matter.
Try this:
That's not documented as working (I'm running Ubuntu Linux), but
echo
is almost certainly a built-in to whatever shell you're using, so the man page is questionable anyway. It does work for me. (I'm runningzsh
because I'm really suave and sophisticated).edit: well it seems that the
bash
builtinedit
doesn't behave that way. I don't know what to suggest; this:will give you "-n" preceded by a space, which (depending on what you're doing) might be OK.
Because the quotes are processed by the shell and the
echo
command receives plain-n
. If you want to echo-n
, you can e.g.printf '%s\n' -n
You could try
you should try to use the more portable
printf
as far as possible.