using bash features in init scripts
Manoj Kumar <[email protected]> Sun, 28 Sep 2003 14:31:04 +0100 (BST)
| Newsgroups | gmane.linux.redhat.devel |
|---|---|
| Message-ID | <[email protected]> |
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.
[email protected]
________________________________________________________________________
Yahoo! India Matrimony: Find your partner online.
Go to http://yahoo.shaadi.com