|
From: | Eric Blake |
Subject: | Re: echo builtin doesn't handle end-of-options flag |
Date: | Sun, 16 Aug 2020 11:30:59 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
On 8/16/20 11:20 AM, Eli Schwartz wrote:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html echo does not accept options, and is not permitted to accept options including "--". bash does accept -n, -e, -E in violation of POSIX, unless shopt -s shopt -s xpg_echo is set, but it doesn't implement -- and I don't really see a justification to do so.
Not quite: https://www.austingroupbugs.net/view.php?id=1222 says that accepting -e and -E will become acceptable in the next revision of POSIX (accepting -n was already acceptable on non-XSI systems).
Either enable xpg_echo or use printf.
POSIX recommends using printf. My personal recommendation is to avoid xpg_echo except when trying to break things - there are a number of what claim to be bash scripts that are not aware of the effects of xpg_echo and which operate incorrectly when you actually set it; whereas using printf is reliably portable.
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |