[PATCH] vars.sh: remove unnecessary fork to speedup boot/upgrades

Thorsten Glaser t.glaser at tarent.de
Mon Sep 14 21:03:01 BST 2020

Did you leave out the mailing list deliberately?
If not, let’s bounce this there for public archival and discussion.

On Mon, 14 Sep 2020, Trek wrote:

> I think it would be better to use the $(cat) construct on those
> bugged /proc files (commenting the code) and a plain read on the others
> what do you think about?

Perhaps with a comment linking to this discussion?

> just another question, as it seems you are the right person to ask
> to print the ansi escape codes for the fancy output on
> lsb/init-functions, I would like to use the printf utility as it works
> reliability on different shells, but mksh (and others) does not have
> this builtin, so in that case echo should be used instead: by chance
> do you know a better approach?

You could use print on all Korn shells, which is guaranteed to be
a builtin there; echo isn’t portable, and especially mksh as /bin/sh
is more likely to have a different echo.

But since these codes are going to be hardcoded, just put a literal
escape sign into the source code. Perhaps once only:

esc='^['	# Ctrl-V Esc in vi, `[ or `+Esc in jupp

This is the optimum.

If you fear that people editing those files can break the code,
add a CI test ensuring ESC is still esc:

test ${#esc} -eq 1 || die esc is not exactly one character
test x"$(printf '%s' "$esc" | tr -dc '\033' | wc -c)" = x"1" || \
    die esc is not the escape character

If you really think you cannot do that, use this:

if test -n "$KSH_VERSION"; then
	esc=$(print -n '\033')
	esc=$(printf '\033')

The upper case catches all Korn shells but ksh86/ksh88,
the other all other shells, if necessary with an external
/usr/bin/printf utility.

„Cool, /usr/share/doc/mksh/examples/uhr.gz ist ja ein Grund,
mksh auf jedem System zu installieren.“
        -- XTaran auf der OpenRheinRuhr, ganz begeistert
(EN: “[…]uhr.gz is a reason to install mksh on every system.”)

More information about the Debian-init-diversity mailing list