help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `printf %q` but more human readable


From: Peng Yu
Subject: Re: `printf %q` but more human readable
Date: Sun, 14 Mar 2021 09:48:55 -0500

On 3/14/21, Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:
> about self coding a solution, i started in gawk, but question: do you want
> \t and \n be shortened or printed

I am not sure. That is where the ambiguity comes from. It will depend
on the real usage. If the string's main purpose is to show tab and
newline explicitly, then they should be encoded in an escaped form,
but if the main purpose is not to show them, then they should not be
escaped. But this is context-dependent. So it may need some trial and
error to be sure which choice is the best. Or it may need to
empirically determine which is the case based on the content of the
whole string.

> and only \34 codes be placed in $' .. '
> otherwise " " otherwise no quotes

It is more than these three cases. '' is also useful in certain cases.
Also, sometimes, splitting the whole string into segments and use a
different style for each segment may also improve readability.

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]