首页 > 其他 > 详细

脚本练习--001

时间:2015-12-31 10:39:01      阅读:226      评论:0      收藏:0      [点我收藏+]

编写脚本,使/etc/rc.d/rc3.d目录下分别有多个以K开头和以S开头的文件,以如下格式输出

    K开头的 后面加stop

    S开头的 后面加start


代码如下:

[root@localhost ~]# cat t1.sh
#!/bin/bash
for file in $(ls /etc/rc.d/rc3.d/);
do
	if [ "$(echo $file |cut -c 1)" == "S" ];
	then
		if [ $(echo $file|wc -c)  -ge 24 ];
		then
			echo -e "$file  start"
		elif [ $(echo $file|wc -c)  -ge 16 ];
		then
			echo -e "$file \t start"
		elif [ $(echo $file|wc -c)  -ge 8 ];
		then
			echo -e "$file \t\t start"
		fi
	else
		if [ $(echo $file|wc -c)  -ge 24 ];
		then
			echo -e "$file  stop"
		elif [ $(echo $file|wc -c)  -ge 16 ];
		then
			echo -e "$file \t stop"
		elif [ $(echo $file|wc -c)  -ge 8 ];
		then
			echo -e "$file \t\t stop"
		fi
	fi
done


执行效果如下:

技术分享

脚本练习--001

原文:http://www1707.blog.51cto.com/1184226/1730205

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!