<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>
Linux 脚本实例
一个 makefile 脚本的例子
脚本化对一个文件进行检查并且如果需要则进行相应的修改。由于它来自于一个makefile, 这个文件类似于一个普通的脚本,带有 ";/"结束符的行表示进行了少量修改。这段内容解释了对rc.local文件的编辑来自于一个 makefile 脚本程序, "printst", 当系统启动的式后可以再后台运行。变量 "BINLOC" 提前在行 "BINLOC = /usr/local/tmp"中定义。可查看在"Making makefiles"开头有关"Making Packages" 的部分。
# 将路径 $(BINLOC)添加到 /etc/rc.d/rc.local 文件内
@PATHIN=`grep "path=" /etc/rc.d/rc.local | grep "$(BINLOC)"`; / # 查看 BINLOC 路径是否被设置在 rc.local 文件内
HEADER=""; /
if /
[ -z "$PATHIN" ]; /
then /
echo Adding $(BINLOC) to path in /etc/rc.d/rc.local; /
echo >> /etc/rc.d/rc.local; /
echo "###### Added by Print Service Install on `date` by `whoami`" >> /etc/rc.d.rc.local; /
HEADER=Y; /
echo "export PATH=/$PATH:$(BINLOC)" >> /etc/rc.d.rc.local; /
else /
echo $(BINLOC) already set in path in file /etc/rc.d/rc.local; /
fi; /
PRINTST=`grep -i "printst &" /etc/rc.d/rc.local`; / # 查看字符串 printst 是否在文件rc.local 内
if /
[ -z "$PRINTST" ]; /
then /
echo Adding printst command to /etc/rc.d/rc.local file; /
if /
[ -z "$HEADER" ]; /
then /
echo >> /etc/rc.d.rc.local; /
echo "###### Added by Print Service Install on `date` by `whoami`" >> /etc/rc.d.rc.local; /
HEADER=Y; /
fi; /
echo "printst &" >> /etc/rc.d.rc.local; /
else /
echo Already have printst command in /etc/rc.d/rc.local file; /
fi; /
if /
[ -n "$HEADER" ]; /
then /
echo "###### End of Print Service Install Section ######" >> /etc/rc.d.rc.local; /
echo >> /etc/rc.d.rc.local; /
fi;