printf: Don't print an error if not given an argument

This commit is contained in:
Fabian Homborg 2020-05-18 19:34:53 +02:00
parent 3cfcbe0975
commit 56f24f08d7
4 changed files with 9 additions and 2 deletions

View File

@ -18,6 +18,7 @@
- Range limits in index range expansions like `$x[$start..$end]` may be omitted: `$start` and `$end` default to 1 and -1 (the last item) respectively.
- `string sub` has a new `--end` option to specify the end index of a substring (#6765).
- `string split` has a new `--fields` option to specify fields to output, similar to `cut -f` (#6770).
- `printf` no longer prints an error if not given an argument (not even a format string)
### Interactive improvements

View File

@ -59,7 +59,9 @@ printf also knows a number of backslash escapes:
- ``\uhhhh`` 16-bit Unicode character (hhhh is 4 digits)
- ``\Uhhhhhhhh`` 32-bit Unicode character (hhhhhhhh is 8 digits)
The ``format`` argument is re-used as many times as necessary to convert all of the given arguments. If a format specifier is not appropriate for the given argument, an error is printed. For example, ``printf '%d' "102.234"`` produces an error, as "102.234" cannot be formatted as an integer.
The ``format`` argument is re-used as many times as necessary to convert all of the given arguments. If the given argument doesn't work for the given format, an error is printed. For example, ``printf '%d' "102.234"`` produces an error, as "102.234" cannot be formatted as an integer. printf will then also return non-zero.
It will also return non-zero if no argument at all was given, in which case it will print nothing.
This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try ``command printf``.

View File

@ -749,7 +749,6 @@ int builtin_printf(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
argc -= optind;
argv += optind;
if (argc < 1) {
streams.err.append_format(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1, argc);
return STATUS_INVALID_ARGS;
}

View File

@ -111,6 +111,11 @@ printf 'long signed %d\n' -498216206595
printf 'long signed to unsigned %u\n' -498216206596
# CHECK: long signed to unsigned 18446743575493345020
# Just check that we print no error for no arguments
printf
echo $status
# CHECK: 2
# Verify numeric conversion still happens even if it couldn't be fully converted
printf '%d\n' 15.1
# CHECK: 15