echo -n does not work as expected - OS X

Users browsing this thread: 1 Guest(s)
seninha
Long time nixers
Echo should not have options.
Each argument of echo should be echoed, so
Code:
echo -n 123
Should print
Code:
-n 123

Quote:And is there a way to make sh on macOS follow the standard so I can make my scripts portable?
Not having -n is the standard way. So echo -n is working as expected.

Here is the comments on -n from the OpenBSD manpage:
Quote:The flag [-n] conflicts with the behaviour mandated by the X/Open System Interfaces option of the IEEE Std 1003.1-2008 (“POSIX.1”) specification, which says it should be treated as part of string. Additionally, echo does not support any of the backslash character sequences mandated by XSI.

echo also exists as a built-in to csh(1) and ksh(1), though with a different syntax.

Where portability is paramount, use printf(1).


Messages In This Thread
echo -n does not work as expected - by jkl - 17-04-2020, 05:26 PM
RE: echo -n does not work as expected - by jkl - 17-04-2020, 05:36 PM
RE: echo -n does not work as expected - by seninha - 17-04-2020, 05:40 PM
RE: echo -n does not work as expected - by z3bra - 20-04-2020, 05:35 AM
RE: echo -n does not work as expected - by jkl - 20-04-2020, 07:04 AM