git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] p5311: handle spaces in wc(1) output

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 4, 2021, 16:16 UTC
Message-ID
<xmqq5yucydcg.fsf@gitster.g>
In-Reply-To
<87wnmuo7ii.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> This approach seems like a bit of plastering over the real problem. It's
> fine to use the output of "wc -l" or "wc -c" in the context of the
> shell's whitespace handling. That's why in various places we do:
Sorry, but I am confused.
Show 10 quoted lines
>     test $(wc -l <$file>) = 1
>
> Or similar, but *don't* put that $() in double-quotes. I.e. we're
> relying on the shell's whitespace semantics.
>
> So isn't it better to just pass this through the shell's own handling
> before emitting the data, something like this POC:
>
>     $ stripspace() { var=$1; echo $@; }; x=$(stripspace "  hi" "  there "); echo "\"$x\""
>     "hi there"

All of the above are not wrong per-se, but if I read the scaffolding code correctly, the way the output from "wc -c" is used is not via a variable, but

    test_size_ () {
            say >&3 "running: $2"
            if test_eval_ "$2" 3>"$base".result; then
                    test_ok_ "$1"
            else
                    test_failure_ "$@"
            fi
    }
    test_size () {
            test_wrapper_ test_size_ "$@"
    }
where "$2" gets the script given to test_size, e.g.
 	test_size "size   $title" '
		wc -c <tmp.pack
 	'

the "wc -c" command. And we just let the command emit its output to "$base.result" (test_eval_ does the stdout-to-#3 redirection, and we redirect #3 back to the file here). So I am not quite sure where in the current system your suggestion to apply the "substitition will lose $IFS around values and gets word splitted if you omit dq around it" would fit to address the issue at hand.

> Of course fixing it up after that in Perl will work just as well, so I
> guess this is just an asthetic preference for having the shell handle
> the shell's output issues with what's guaranteed to be shell-portable
> solutions... :)

Meaning we could rewrite aggregation in shell, then we can say we are not making Perl clean up after mess sh creates? I dunno...

Thanks.
Previous: Ævar Arnfjörð BjarmasonNext: Jeff King
Message 4 of 5 in “p5311: handle spaces in wc(1) output”
  1. p5311: handle spaces in wc(1) outputRené Scharfe, Oct 2, 2021
  2. Taylor BlauOct 3, 2021
  3. Ævar Arnfjörð BjarmasonOct 3, 2021
  4. Junio C HamanoOct 4, 2021
  5. Jeff KingOct 4, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.