<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr"><div>Just a quick note with a suggestion for an improvement in the killproc() function in the shell script /lib/lsb/init-functions:</div><div><br></div><div>It uses <span style="font-family:monospace">${1##*/}</span> to get the basename of arg 1</div><div>but then for arg 2 it uses the heftier $( echo .. | sed ... ) construct.</div><div>This could be made much lighter weight using the same ## operator.</div><div>Specifically, lines 147, 148 read:</div><div><span style="font-family:monospace"> sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')<br> sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')</span></div><div>but could be simplified to:</div><div><span style="font-family:monospace"> sig=${2#-}</span></div><div><span style="font-family:monospace"> sig=${sig#SIG}</span></div><div>thereby avoiding the subshell ( the <span style="font-family:monospace">$()</span> ) and the exec of sed.</div><div>Or am I missing some other desired behavior or side effect?</div><div><br></div><div>Here's a simple test case:<br></div><div><span style="font-family:monospace">comparem() {<br> sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')<br> sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')<br><br> new=${2#-}<br> new=${new#SIG}<br><br> echo $sig $new<br>}<br></span></div><div><span style="font-family:monospace"># should get the same results for both:<br></span></div><div><span style="font-family:monospace">comparem with -15<br>comparem with SIG15<br>comparem with -SIG15</span><br></div><div><br></div><div>#-----------------<br></div><div><br></div><div>Hope this is a help. (My version comes from Ubuntu 20.04.)<br></div><div>Thanks, too, for being part of the great Linux OS ecosystem.<br></div><div><br></div><div> - Carl</div><div><br></div><div>Carl Albing</div><div>(co-author, O'Reilly's "bash Cookbook")<br></div></div>
</div></div>