Re: Corner case bug caused by shell dependent behavior
- From
David Kastrup <dak@gnu.org>
- Date
- Mar 14, 2014, 06:08 UTC
- Message-ID
- <87d2hpgvmj.fsf@fencepost.gnu.org>
- In-Reply-To
- <20140314022845.GA19757@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 16 quoted lines
> Hmph. We ran into this before and fixed all of the sites (e.g., d1c3b10
> and 938791c). This one appears to have been added a few months later
> (by 68d5d03).
>
>> Maybe there are more places where it would be more robust to use
>> printf instead of echo.
>
> FWIW, I just looked through the other uses of "echo" in git-rebase*.sh,
> and I think this is the only problematic case.
>
>> - echo "$sha1 $action $prefix $rest"
>> + printf "%s %s %s %s\n" "$sha1" "$action" "$prefix" "$rest"
>
> Looks obviously correct. The echo just below here does not need the same
> treatment, as "$rest" is the problematic bit ("$prefix" is always
> "fixup" or "squash").I'd not rationalize this away by deep analysis. Copy&paste is a thing, so to just use printf whenever _any_ seriously variable strings (source not immediately the shell script itself, perhaps even _any_ nonconstant strings) are involved keeps people from introducing bugs by following apparent practice.
-- David Kastrup