Re: using bash features in init scripts

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

 



On Sunday, Sep 28th 2003 at 14:31 +0100, quoth Manoj Kumar:

=>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.

You have my blessing. 


-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question?
steveo at syslang.net


_______________________________________________
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