[PATCH] quote arguments in xtrace output

Denys Vlasenko vda.linux at googlemail.com
Sun Mar 19 19:18:46 UTC 2017


Is it in dash git already?

Can you ping me when it reaches dash git?

On Sat, Mar 18, 2017 at 6:45 AM, Martijn Dekker <martijn at inlv.org> wrote:
> The xtrace (set -x) output in ash is a bit of a pain, because arguments
> containing whitespace aren't quoted. This can make it impossible to tell
> which bit belongs to which argument:
>
> $ ash -x -c 'somevar="one two" printf %s\\n one "two three" four'
> + somevar=one two printf %s\n one two three four
> one
> two three
> four
>
> Another disadvantage is you cannot simply copy and paste the commands
> from this xtrace output to repeat them for debugging purposes.
>
> I wrote the attached patch which fixes this. It's based on one I wrote
> for dash a few weeks ago. That version has gone through a few
> iterations, with input from Harald van Dijk, whose suggestions are
> incorporated here as well.
>
> The patch changes the following:
>
> (1) Since we don't want every command name and argument quoted but only
> those needed for safe re-input into the shell, single_quote() has
> acquired an extra argument indicating whether quoting should be
> conditional (1) or unconditional (0). Conditional quoting quotes the
> string only if it contains characters that are not shell-safe, or is
> identical to a shell keyword (reserved word), or is empty.
> Shell-safe characters are defined as this set:
> 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz%+,./:@_^-
>
> (2) Printing of variable assignments preceding commands is handled
> specially; in order for the output to be suitable for re-entry into the
> shell, only the part after the "=" is quoted.
>
> (3) While we're at it, the values in the output of "set" (list of all
> variables and their values) are quoted conditionally like in bash.
>
> After the patch:
>
> $ ash -x -c 'somevar="one two" printf %s\\n one "two three" four'
> + somevar='one two' printf '%s\n' one 'two three' four
> one
> two three
> four
>
> For further background, see the thread on the dash list:
> https://www.mail-archive.com/dash@vger.kernel.org/#01317
>
> Hope this is useful,
>
> - Martijn
>
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox


More information about the busybox mailing list