Article View: alt.folklore.computers
Article #967Re: Portability of 'echo -n'
From: Geoff Clare
Date: Mon, 09 Nov 2026 14:38
Date: Mon, 09 Nov 2026 14:38
41 lines
3075 bytes
3075 bytes
Waldek Hebisch wrote: > 'echo -n' is standard, AFAIK it is GNU standard and compatible > with Posix. It seems that only Unix compliance disallows it. > Given long history, widespread use and utility there should be > very strong reason to disallow it. I am not aware of such a > reason. "echo -n" suppressing newline is historical BSD behaviour. "echo -n" writing "-n" and a newline is historical System V behaviour (with "\c" on the end of the string suppressing newline). When the POSIX and XPG/SUS standards were developed in the late 1980's and early 1990's, the POSIX.2 authors decided to allow both behaviours, whereas the XPG authors decided to require the System V behaviour. (At the time they were separate standards.) When POSIX.1, POSIX.2 and SUSv2 were merged in 2001, no doubt there was a discussion of whether to keep the System V behaviour when the XSI option is supported. Relaxing the standard to allow both behaviours regardless of whether XSI is supported would have broken long-established uses of echo on XPG and SUSv1/2 conforming systems. Bash supports both behaviours, selectable via the bash-specific "shopt" built-in or via the corresponding BASHOPTS environment variable: $ sh --version | head -n 1 GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu) $ sh -c 'echo -n foo; echo' foo $ env BASHOPTS=xpg_echo sh -c 'echo -n foo' -n foo I don't know whether Apple made xpg_echo the default in their version of bash or if they expect systems (or individual users) to set BASHOPTS if they want a SUS "conforming environment". -- Geoff Clare <netnews@gclare.org.uk>
Technical Details
Message-ID:
<1h29sm-a9t.ln1@ID-313840.user.individual.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mailReferences:
<11bujmd$31udl$1@dont-email.me> <qg3prm-ql7.ln1@ID-313840.user.individual.net> <11cdgp6$46jl$5@dont-email.me> <fcqrrm-5o6.ln1@ID-313840.user.individual.net> <11cg8q2$12d33$1@dont-email.me> <eceurm-lq4.ln1@ID-313840.user.individual.net> <11cijp9$1sunb$1@dont-email.me> <n231sm-d23.ln1@ID-313840.user.individual.net> <11ckp2g$2jqjg$2@dont-email.me> <11cl5im$2nftp$3@dont-email.me> <11cli6u$2u21d$1@paganini.bofh.team> <11clrnu$3188f$1@dont-email.me> <11cmsv6$3a9pr$2@dont-email.me> <11co4v2$37o9q$2@paganini.bofh.team>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Geoff Clare <geoff@clare.See-My-Signature.invalid> Newsgroups: alt.folklore.computers Subject: Re: Portability of 'echo -n' Date: Mon, 9 Nov 2026 14:38:57 +0000 Lines: 41 Message-ID: <1h29sm-a9t.ln1@ID-313840.user.individual.net> References: <11bujmd$31udl$1@dont-email.me> <qg3prm-ql7.ln1@ID-313840.user.individual.net> <11cdgp6$46jl$5@dont-email.me> <fcqrrm-5o6.ln1@ID-313840.user.individual.net> <11cg8q2$12d33$1@dont-email.me> <eceurm-lq4.ln1@ID-313840.user.individual.net> <11cijp9$1sunb$1@dont-email.me> <n231sm-d23.ln1@ID-313840.user.individual.net> <11ckp2g$2jqjg$2@dont-email.me> <11cl5im$2nftp$3@dont-email.me> <11cli6u$2u21d$1@paganini.bofh.team> <11clrnu$3188f$1@dont-email.me> <11cmsv6$3a9pr$2@dont-email.me> <11co4v2$37o9q$2@paganini.bofh.team> Reply-To: netnews@gclare.org.uk Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 9vcUN/qSiJY8U+res6q06QkW08swMzdtuRz9sK593osHcMM0RI X-Orig-Path: ID-313840.user.individual.net!not-for-mail Cancel-Lock: sha1:wonusGVCSF3BJ8IWGJsDH+UtpO0= sha256:wu2JDMLSZ6mTyjejOvQ/iugrjgAEqycLMdbYVnBn+B8= User-Agent: Pan/0.154 (Izium; 517acf4)