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

Re: Need bash-programmer for file-rc



On Tue, 31 Mar 1998, Martin Schulze wrote:

> > i think you're mistaken that bash will be faster than perl for this.
> > 
> > the overhead of executing sed (and/or awk and/or perl) numerous times to
> 
> No sed
> No awk
> No cut
> No what else?
> 
> ONLY bash.  If you know bash you know how to write scripts that make
> only use of bash's features.
> 
> I'm sorry but I have to object, it is n times faster that a similar
> script in e.g. perl.

ok, i'll take that as a challenge :-)

it seems that you were right and i was wrong. it isn't actually very
difficult to code in bash.  in fact, it looks like it's doable in plain sh
without any bash-specific stuff.

here's a first stab at it. note that it doesn't actually do anything
- it just parses the stop and start options (i'll leave "defaults"
and "remove" as an exercise for the reader :) there's also no error
checking. it's just a rough skeleton of how it might be done. enjoy.


---cut here---
#! /bin/sh

set -x

DO_START () {
    # $1 init.d script
    # $2 NN
    # $3 run-level

    echo ln -s /etc/init.d/$1 /etc/rc$3.d/S$2$1
}

DO_STOP () {
    # $1 init.d script
    # $2 NN
    # $3 run-level

    echo ln -s /etc/init.d/$1 /etc/rc$3.d/K$2$1
}

DO_DEFAULTS () {
}

DO_REMOVE () {
}

while [ -n "$1" ] ; do 
    case "$1" in
        start)  shift
                NN="$1" 
                shift
                while [ "$1" != "." ] ; do
                    DO_START $script $NN $1
                    shift
                done
                ;;

        stop)   shift 
                NN="$1"
                while [ "$1" != "." ] ; do
                    DO_STOP $script $NN $1
                    shift
                done
                ;;

        defaults)  # nothing here yet
                ;;
        remove)  # nothing here yet
                ;;
        *) script=$1
                ;;
    esac
    shift
done
---cut here---



craig

--
craig sanders

Reply to: