using bash features in init scripts

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

 



Is there any reason not to use bash features in init
scripts?
Consider, for example, this fragment from
/etc/sysconfig/network-scripts/ifup-post:

    DEVICETYPE=`echo $DEVICE | sed "s/[0-9]*$//"`
    REALDEVICE=`echo $DEVICE | sed 's/:.*//g'`
    if echo $DEVICE | grep -q ':' ; then
        ISALIAS=yes
    else
        ISALIAS=no
    fi

In bash we can do this much faster with something like
this:

    DEVICETYPE=$DEVICE
    while [[ $DEVICETYPE == *[0-9] ]]; do
        DEVICETYPE=${DEVICETYPE%[0-9]}
    done
    REALDEVICE=${DEVICE%%:*}
    if [[ $DEVICE == *:* ]]; then
        ISALIAS=yes
    else
        ISALIAS=no
    fi

Okay, the loop that replaces the first line is messy,
but it saves
a couple of forks and an exec.  The other two changes
are both
simpler and faster.

So why do most init scripts use sed and grep to
process
strings?  It can't be a desire to allow them to work
with the
Bourne shell (why would we want that anyway?) because
some
scripts do use bash features.

manojkumar_137@xxxxxxxxxxx


________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com


_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux