(please Cc me, I'm not on the list, just found it on gmane)

Petr Salinger dixit:

> Proper fix would be write "sort -u" using only /bin a /sbin binaries.

For this task, maybe a uniq-without-sort would be enough. Something like
this (at least works in mksh, maybe it's portable enough for /bin/sh):

--- module-init-tools.orig      Wed May 16 19:05:53 2007
+++ module-init-tools   Wed May 16 19:09:37 2007
@@ -27,12 +27,14 @@ do_start() {
        for i in load stat unload ; do
                which kld$i >/dev/null || exit 1
        done
-       modules="`shopt -s nullglob ; cat /etc/modules /etc/modules.d/* \
-                | sed -e \"s/#.*//g\" -e \"/^\( \|\t\)*$/d\" | sort | uniq`"
-
-       set -e
-
-       for i in ${modules} ; do
+       mods=:
+       cat /etc/modules /etc/modules.d/* 2>/dev/null | \
+           sed -e 's/#.*$//g' -e '/^[   ]*$/d' | \
+           while read i; do
+               case $mods in
+               *:$i:*) continue ;;
+               esac
+               mods=$mods$i:
                if ! kldstat -n $i >/dev/null 2>/dev/null ; then
                        echo "Loading $i ..."
                        kldload $i || true


I've just tried this and it works for me, maybe I didn't cover corner
cases, but it looks okay, and the autoconf texinfo manual (section
portable shell) tells me there is no additional quoting needed either.

Bonus: the bash-only “shopt” is gone as well!

HTH&HAND,
//mirabile

PS: If you got any other shell scripting tasks, feel free to come to me.
-- 
I believe no one can invent an algorithm. One just happens to hit upon it
when God enlightens him. Or only God invents algorithms, we merely copy them.
If you don't believe in God, just consider God as Nature if you won't deny
existence.              -- Coywolf Qi Hunt

Reply via email to