mirror of
https://github.com/coreutils/coreutils.git
synced 2026-10-28 09:44:34 +08:00
doc: say that printf(1) is preferred over echo(1)
* src/echo.c (usage): Say printf(1) is preferred due to being more standard and robust. * man/echo.x [SEE ALSO]: Reference printf(1). * doc/coreutils.texi (echo invocation): Mention in the summary that echo is not robust when outputting any string, and that printf is preferred. Also expand on the examples showing how to output a single '-n' string. Addresses https://bugs.gnu.org/51311
This commit is contained in:
1 parent
13af84d09a
commit
f60a3981c3
3 files changed
+19
-4
No files matched your search
+13
-4
@@ -12896,6 +12896,13 @@ echo [@var{option}]@dots{} [@var{string}]@dots{}
|
||||
|
||||
@mayConflictWithShellBuiltIn{echo}
|
||||
|
||||
Due to historical and backwards compatibility reasons, certain bare option-like
|
||||
strings cannot be passed to @command{echo} as non-option arguments.
|
||||
It is therefore not advisable to use @command{echo} for printing unknown or
|
||||
variable arguments. The @command{printf} command is recommended as a more
|
||||
portable and flexible replacement for tasks historically performed by
|
||||
@command{echo}. @xref{printf invocation}.
|
||||
|
||||
The program accepts the following options. Also see @ref{Common options}.
|
||||
Options must precede operands, and the normally-special argument
|
||||
@samp{--} has no special meaning and is treated like any other
|
||||
@@ -12961,13 +12968,15 @@ If the @env{POSIXLY_CORRECT} environment variable is set, then when
|
||||
option-like arguments instead of treating them as options. For
|
||||
example, @code{echo -ne hello} outputs @samp{-ne hello} instead of
|
||||
plain @samp{hello}. Also backslash escapes are always enabled.
|
||||
Note to echo the string @samp{-n}, one of the characters
|
||||
can be escaped in either octal or hexadecimal representation.
|
||||
For example, @code{echo -e '\x2dn'}.
|
||||
|
||||
POSIX does not require support for any options, and says
|
||||
that the behavior of @command{echo} is implementation-defined if any
|
||||
@var{string} contains a backslash or if the first argument is
|
||||
@option{-n}. Portable programs can use the @command{printf} command
|
||||
if they need to omit trailing newlines or output control characters or
|
||||
backslashes. @xref{printf invocation}.
|
||||
@var{string} contains a backslash or if the first argument is @option{-n}.
|
||||
Portable programs should use the @command{printf} command instead.
|
||||
@xref{printf invocation}.
|
||||
|
||||
@exitstatus
|
||||
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
echo \- display a line of text
|
||||
[DESCRIPTION]
|
||||
.\" Add any additional description here
|
||||
[SEE ALSO]
|
||||
printf(1)
|
||||
@@ -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,\n\
|
||||
which does not have issues outputting option-like strings.\n\
|
||||
"), stdout);
|
||||
emit_ancillary_info (PROGRAM_NAME);
|
||||
exit (status);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user