Subject: Re: bug#51311: [PATCH] echo: update --help to document edge cases
From: Pádraig Brady <[email-masked]>
To: Florent Flament <[email-masked]>, [email-masked]
Cc: [email-masked]
Date: Thu, 21 Oct 2021 13:11:25 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

On 20/10/2021 22:50, Florent Flament wrote:
> 
> * src/echo.c (usage): Document edge cases when displaying arbitrary
> strings with the echo command.
> ---
>   src/echo.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/src/echo.c b/src/echo.c
> index 18513398a..73b44660b 100644
> --- a/src/echo.c
> +++ b/src/echo.c
> @@ -78,6 +78,14 @@ If -e is in effect, the following sequences are recognized:\n\
>     fputs (_("\
>     \\0NNN   byte with octal value NNN (1 to 3 digits)\n\
>     \\xHH    byte with hexadecimal value HH (1 to 2 digits)\n\
> +"), stdout);
> +  fputs (_("\
> +\n\
> +NOTE: The echo command doesn't behave gracefully when displaying\n\
> +arbitrary strings. For example, it can't display the string \"-n\" and\n\
> +requires the STRICTLY_POSIX flag to display \"-e\" or \"-E\". Therefore,\n\
> +if you need to display arbitrary strings please use the printf command\n\
> +instead.\n\
>   "), stdout);
>     printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
>     emit_ancillary_info (PROGRAM_NAME);

This is too verbose.
BTW the env var is POSIXLY_CORRECT, not STRICTLY_POSIX.
Anyway I don't think we should mention that in the man page anyway.
I'll push the attached later, which just says printf(1) is preferred.

cheers,
Pádraig

From 0aaa7e4ad33f9cf89d525bda0f9bfe3f9b092288 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email-masked]>
Date: Thu, 21 Oct 2021 13:05:47 +0100
Subject: [PATCH] doc: say that printf(1) is preferred over echo(1)

* src/echo.c (usage): Say printf(1) is preferred
due to being more standard.
* man/echo.x [SEE ALSO]: Reference printf(1).
---
 man/echo.x | 2 ++
 src/echo.c | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/man/echo.x b/man/echo.x
index 9c4fa8131..61a36706b 100644
--- a/man/echo.x
+++ b/man/echo.x
@@ -2,3 +2,5 @@
 echo \- display a line of text
 [DESCRIPTION]
 .\" Add any additional description here
+[SEE ALSO]
+printf(1)
diff --git a/src/echo.c b/src/echo.c
index 18513398a..d2262fa6b 100644
--- a/src/echo.c
+++ b/src/echo.c
@@ -80,6 +80,10 @@ If -e is in effect, the following sequences are recognized:\n\
   \\xHH    byte with hexadecimal value HH (1 to 2 digits)\n\
 "), stdout);
   printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
+  fputs (_("\n\
+NOTE: printf(1) is a preferred alternative, with more standard option handling.\
+\n\
+"), stdout);
   emit_ancillary_info (PROGRAM_NAME);
   exit (status);
 }
-- 
2.26.2