Feature #721
echo does not support -n flag
0%
Description
The -n flag prevents echo from printing a newline
Updated by Rich Lowe about 10 years ago
One of the classic differences between UCB and SYSV echo(1). UCB echo uses -n, SYSV has a "\c" escape that prevents the trailing newline and accepts no flags (so its arguments, whatever they may be, are echoed literally). Use /usr/ucb/echo -n, /usr/gnu/bin/echo -n, or echo "foo\c" as a workaround.
At this point, I wouldn't be shocked to find we were the last hold-out of SYSV-style echo(1), though, as far as concerns for compatibility go.
Updated by Roland Mainz about 10 years ago
Technically NO new application should ever use "echo".
Please please please use "printf" (e.g. /usr/bin/printf ... and bash+ksh93 have "printf" builtin shell utilties) for this purpose - it was invented by the POSIX/SUS people to end the neverending horror of "echo".
Thanks...
Updated by Garrett D'Amore about 10 years ago
- Status changed from New to Rejected
Actually, supporting -n, while at first sounding like a good idea, would explicitly violate the POSIX standards:
http://www.opengroup.org/onlinepubs/000095399/utilities/echo.html
So, we can't add n - as already indicated, this is a historic SYSV vs. BSD difference, and we won't be changing it. The "portable" way is to do printf(1) - of course many scripts have special logic to test for echo -n vs. echo "\c".