[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xargs prompts with the same string, but executes differently
From: |
Bernhard Voelker |
Subject: |
Re: xargs prompts with the same string, but executes differently |
Date: |
Wed, 24 Jul 2019 23:20:06 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 |
On 7/24/19 4:30 PM, Eric Blake wrote:
> On 7/24/19 6:28 AM, James Youngman wrote:
>> On Tue, Jul 23, 2019 at 7:51 PM 積丹尼 Dan Jacobson <address@hidden> wrote:
>>>
>>> OK.
>>> But I now "demand" that xargs add a --show-quoting or whatever argument,
>>
>> Your demand must be presented in the form of a patch.
>
> Is a new option necessary, or can we just use gnulib's quotearg() module
> unconditionally? I guess the only reason to make it a new command-line
> option would be to allow the user to specify which of the quotearg
> styles they prefer to see (for reference, 'ls --quoting-style=WORD' is a
> good example of producing various representations of the output to avoid
> ambiguities). If we do use gnulib's quotearg module, we also benefit
> from QUOTING_STYLE in the environment regardless of whether we add a
> command-line option.
I agree that another new option is way too much. That question to the user
is meant for interactive use only anyway, so what about simply:
diff --git a/xargs/xargs.c b/xargs/xargs.c
index 913328b8..85084123 100644
--- a/xargs/xargs.c
+++ b/xargs/xargs.c
@@ -1093,7 +1093,7 @@ print_args (bool ask)
for (i = 0; i < bc_state.cmd_argc - 1; i++)
{
- if (fprintf (stderr, "%s ", bc_state.cmd_argv[i]) < 0)
+ if (fprintf (stderr, "%s ", quotearg_n_style (0,
shell_escape_quoting_style, bc_state.cmd_argv[i])) < 0)
die (EXIT_FAILURE, errno, _("Failed to write to stderr"));
}
Example:
$ printf '%s\0' 000 '0 0' '0"0' "0'0" \
| xargs/xargs -0p '-I{}' echo hello '{}' world
echo hello 000 world ?...y
hello 000 world
echo hello '0 0' world ?...y
hello 0 0 world
echo hello '0"0' world ?...y
hello 0"0 world
echo hello "0'0" world ?...y
hello 0'0 world
Well, this also changes plain -t output (i.e., without -p), but it's not
that bad actually: it doesn't seem to be specified anywhere how -t output
should look like. Just in case, we could still guard quotearg_n_style
by "if (ask)".
Do you see any drawback / corner case?
Have a nice day,
Berny
- xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/23
- Re: xargs prompts with the same string, but executes differently, Assaf Gordon, 2019/07/23
- Re: xargs prompts with the same string, but executes differently, Eric Blake, 2019/07/23
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/23
- Re: xargs prompts with the same string, but executes differently, James Youngman, 2019/07/24
- Re: xargs prompts with the same string, but executes differently, Eric Blake, 2019/07/24
- Re: xargs prompts with the same string, but executes differently,
Bernhard Voelker <=
- Re: xargs prompts with the same string, but executes differently, Eric Blake, 2019/07/24
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/25
- Re: xargs prompts with the same string, but executes differently, James Youngman, 2019/07/25
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/25
- Re: xargs prompts with the same string, but executes differently, Bernhard Voelker, 2019/07/29
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/29
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/29
- Re: xargs prompts with the same string, but executes differently, Eric Blake, 2019/07/29
- Re: xargs prompts with the same string, but executes differently, 積丹尼 Dan Jacobson, 2019/07/29
- Re: xargs prompts with the same string, but executes differently, Bernhard Voelker, 2019/07/29