pure bash, grep, sed??? best solution?

DJ Lucas dj_me at swbell.net
Fri Sep 6 05:44:41 PDT 2002


Take the runlevel command, it returns two values

bash-2.05a# runlevel
N 3
bash-2.05a# _

in my infinate wisdom of bash LOL (yeah right), i currently have a
script that's about 200 lines long, consisting of an if-then statement
for every single possibility.  While this has worked fine for my test
case, it's hardly practical.  What would be a better solution?  End
result is:  I want a file (/var/cache/rlstate) that defines two
variables (PRL and CRL) also currently this is run at S99rltest (so the
variable is there at startup) in RLs 1-5, and at K01rltest (so the
variable is current immediately after switching RLs to create a valid
test condition) in RLs 0-6.


Current script for an example:
___________________________________________________________
# Begin /etc/rc.d/init.d/rltest
rm -f /var/cache/rltmp
rm -f /var/cache/rlstate
echo -n 'RLTEST="' >> /var/cache/rltmp
echo $(runlevel)'"' >> /var/cache/rltmp
## the echo statements above after a standard boot result in a file that
contians
## a single line that reads ' RLTEST="N 3" '
## and below I have a bunch of  if then statements similar to the next
one for each
## possible condition

# source the newly created file
source /var/cache/rltmp
if [ "$RLTEST" == "N 3" ]
then
    echo 'PRL=N' >> /var/cache/rlstate
    echo 'CRL=3' >> /var/cache/rlstate
fi
## etc.....
# clean up my mess
rm -f /var/cache/rltmp
# End /etc/rc.d/init.d/rltest
______________________________________________________________

bash-2.05a# more /var/cache/rlstate
PRL=N
CRL=3
bash-2.05a# _



-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-chat' in the subject header of the message



More information about the lfs-chat mailing list