I have a problem with echo
in my script:
echo -n "Some string..."
prints
-n Some string...
and moves to the next line. In the console it's working correcly without newline:
Some string...
I have a problem with echo
in my script:
echo -n "Some string..."
prints
-n Some string...
and moves to the next line. In the console it's working correcly without newline:
Some string...
bash
has a "built-in" command called "echo":Additionally, there is an "echo" command that is a proper executable (that is, the shell forks and execs
/bin/echo
, as opposed to interpretingecho
and executing it):The behavior of either
echo
's WRT to\c
and-n
varies. Your best bet is to useprintf
, which is available on four different *NIX flavors that I looked at:If you use echo inside an if with other commands, like "read", it might ignore the setting and it will jump to a new line anyway.
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
.The
printf
command has much more consistent behavior.echo
is fine for simple things likeecho hello
, but I suggest usingprintf
for anything more complicated.What system are you on, and what shell does your script use?
Try with
It works for me as expected (as I understood from your question).
Note that I got this information from the
man
page. Theman
page also notes the shell may have its own version ofecho
, and I am not sure ifbash
has its own version.