Fwd: /lib/lsb/init-functions

Carl Albing carl-albing at bethel.edu
Wed Aug 5 21:05:37 BST 2020


Just a quick note with a suggestion for an improvement in the killproc()
function in the shell script /lib/lsb/init-functions:

It uses ${1##*/} to get the basename of arg 1
but then for arg 2 it uses the heftier $( echo .. | sed ... ) construct.
This could be made much lighter weight using the same ## operator.
Specifically, lines 147, 148 read:
    sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')
    sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')
but could be simplified to:
    sig=${2#-}
    sig=${sig#SIG}
thereby avoiding the subshell ( the $() ) and the exec of sed.
Or am I missing some other desired behavior or side effect?

Here's a simple test case:
comparem() {
    sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')
    sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')

    new=${2#-}
    new=${new#SIG}

    echo $sig $new
}
# should get the same results for both:
comparem with -15
comparem with SIG15
comparem with -SIG15

#-----------------

Hope this is a help.  (My version comes from Ubuntu 20.04.)
Thanks, too, for being part of the great Linux OS ecosystem.

 - Carl

Carl Albing
(co-author, O'Reilly's "bash Cookbook")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.chiark.greenend.org.uk/pipermail/debian-init-diversity/attachments/20200805/045f5279/attachment.html>


More information about the Debian-init-diversity mailing list