08 2016 档案

shell脚本,当用sed删除某一文件里面的内容时,并追加到同一个文件会出现问题。
摘要:shell脚本,当用sed删除某一文件里面的内容时,并追加到同一个文件会出现问题。因为初始文件和写入文件是一个文件这是失败的。需要追加到另一个文件,然后再用mv进行操作。[root@localhost wyb]# seq 10 > 10.txt [root@localhost wyb]# cat 10.txt 1 2 3 4 5 6 7 8 9 10 [root@localhost wyb]# ... 阅读全文

posted @ 2016-08-31 15:24 王月波 阅读(2896) 评论(0) 推荐(0) 编辑

shell脚本,按行读取文件的几种方法。
摘要:第一种方法用while实现按读取文件。[root@localhost wyb]# cat a.txt 第一行 aaaaaa 第二行 bbbbbb 第三行 cccccc 第四行 dddddd 第五行 eeeeee [root@localhost wyb]# cat anhang.sh #!/bin/bash cat a.txt| while read line do ... 阅读全文

posted @ 2016-08-31 10:44 王月波 阅读(22955) 评论(1) 推荐(0) 编辑

shell脚本,锁机制
摘要:[root@localhost wyb]# cat suijizhi.sh #!/bin/bash a=`ps -ef|grep $0|grep -v grep |wc -l` echo "$a" [ $a -ne 2 ] && echo "123" && exit 1 for i in `seq 10` do sleep 1000 done [root@localhost wy... 阅读全文

posted @ 2016-08-30 23:13 王月波 阅读(896) 评论(0) 推荐(0) 编辑

shell脚本,通过一个shell程序计算n的阶乘。
摘要:[root@localhost ~]# cat jiechen.sh #!/bin/bash #设计一个shell程序计算n的阶乘,要求: #1.从命令行接收参数n; #2.在程序开始后立即判断n的合法性,即是否有参数,若有是否为正整数,若非法请给错误提示。 #3.最后出计算的结果 num=$1 expr $num + 1 &>/dev/null [ $? -ne 0 ] && echo "... 阅读全文

posted @ 2016-08-30 20:45 王月波 阅读(18398) 评论(0) 推荐(1) 编辑

shell脚本,如何写进度条。
摘要:[root@localhost ~]# cat jindutiao.sh #!/bin/bash #进度条 n=$((100/10)) N=$((100/20)) for i in `seq 500` do sleep 0.01 [ $(($i%$n)) -eq 0 ] && echo -ne "\b=" && continue [ $(($i%$N)) -eq 0 ... 阅读全文

posted @ 2016-08-30 20:42 王月波 阅读(5659) 评论(0) 推荐(0) 编辑

shell脚本,判断给出的字符串是否相等。
摘要:第一种方法[root@localhost wyb]# cat 11.sh #!/bin/bash #判断给出的字符串是否相等 read -p "Please Input a number:" number [ -z $number ] && echo 'Input nothing' && exit 1 len=${#number} a=`echo $number|cut -c 1` fo... 阅读全文

posted @ 2016-08-30 20:38 王月波 阅读(13590) 评论(0) 推荐(0) 编辑

shell脚本,提取ip地址和子网掩码,和查外网ip地址信息。
摘要:#提取IP地址和子网掩码 [root@localhost ~]# ifconfig eth0|grep 'inet addr'|awk -F'[ :]+' '{print $4"/"$8}' 192.168.16.110/255.255.255.0 [root@localhost ~]# #查外网IP地址 [root@localhost ~]# curl -s ipe... 阅读全文

posted @ 2016-08-30 20:28 王月波 阅读(3788) 评论(0) 推荐(0) 编辑

shell脚本,按空格开始60秒的倒计时。
摘要:[root@localhost wyb]# cat space.sh #!/bin/bash #按空格开始60秒的倒计时#-n表示接受字符的数量,1表示只接受一个字符 a() { for i in `seq -w 60 -1 0` do echo -ne "\b\b$i" sleep 0.1 done echo "" } read -n 1 -p "[ Pr... 阅读全文

posted @ 2016-08-30 20:23 王月波 阅读(3920) 评论(0) 推荐(0) 编辑

shell脚本,计算创建100个文件所用多少时间。
摘要:[root@localhost mulu]# ls [root@localhost mulu]# time for i in `seq 100`; do touch file$i; done real 0m0.104s user 0m0.012s sys 0m0.090s [root@localhost mulu]# ls file1 file13 file18 f... 阅读全文

posted @ 2016-08-30 14:19 王月波 阅读(1197) 评论(0) 推荐(0) 编辑

shell脚本,计算输入给定的数,判断最大值,最小值,总和?
摘要:[root@localhost ~]# cat five.sh #!/bin/bash #任意输入5个数,判断最大值,最小值,总和 s=0 read -p "please input:" num s=$(($s+$num)) max=$num min=$num for i in `seq 4` do read -p "please input:" num s=$(... 阅读全文

posted @ 2016-08-29 17:04 王月波 阅读(9264) 评论(0) 推荐(0) 编辑

shell脚本,编写1个弹出式菜单的shell程序并实现其简单的菜单功能。
摘要:[root@localhost wyb]# cat zonghe.sh #!/bin/bash #zonghe usage(){ case $choice in 1) read -p "please input the old file and new file : " old_file new_file cp -r $old_file $new_file if [ $? -eq 0 ]... 阅读全文

posted @ 2016-08-29 16:50 王月波 阅读(8080) 评论(0) 推荐(0) 编辑

shell脚本,创建50个文件,删除50个文件。
摘要:[root@localhost ~]# cat create50.sh #!/bin/bash #创建50个文件 for i in `seq 50` do touch student$i done echo "创建50个文件成功!" [root@localhost ~]# bash create50.sh 创建50个文件成功! [root@localhost ~... 阅读全文

posted @ 2016-08-29 15:57 王月波 阅读(7933) 评论(0) 推荐(0) 编辑

shell脚本,打印九九乘法表。
摘要:利用AWK求99乘法表 阅读全文

posted @ 2016-08-29 14:51 王月波 阅读(13160) 评论(2) 推荐(0) 编辑

shell脚本,计算1+3+5....100等于多少?
摘要:[root@localhost wyb]# cat unevenjia.sh #!/bin/bash #从1+3+5+7。。。100的结果 sum=0 i=1 count=$1 for i in `seq 1 2 $count` do sum=$(($sum+i)) i=$(($i+2)) done echo 1+3+5+7+9+...100等于:$sum [root@localh... 阅读全文

posted @ 2016-08-29 14:47 王月波 阅读(968) 评论(0) 推荐(0) 编辑

shell脚本,计算从0+2+4+6+....100的结果是多少?
摘要:[root@localhost wyb]# cat evenjia.sh #!/bin/bash #从0+2+4+6+。。。100的结果 sum=0 i=0 for i in `seq 0 2 100` do sum=$(($sum+i)) i=$(($i+2)) done echo 0+2+4+6+...100等于:$sum [root@localhost wyb]# ba... 阅读全文

posted @ 2016-08-29 14:41 王月波 阅读(1234) 评论(0) 推荐(0) 编辑

shell脚本,计算1+2+3+....100等于多少?
摘要:第一种方法,通过for循环来计算[root@localhost wyb]# cat yibai.sh #!/bin/bash #从1+2+3+。。。100的结果 sum=0 i=1 for i in `seq 1 100` do sum=$(($sum+i)) i=$(($i+1)) done echo 1+2+3+...100:$sum [root@localhost wyb... 阅读全文

posted @ 2016-08-29 14:12 王月波 阅读(11392) 评论(0) 推荐(0) 编辑

shell脚本,通过传参求斐波那契数列如(0,1,1,2,3,5,8,13..........)
摘要:[root@localhost wyb]# cat fibo.sh #!/bin/bash #斐波那契数列 0,1,1,2,3,5,8,13 echo 0 > file echo 1 >> file count=$1 for i in `seq $count` do first=$(tail -2 file |head -1) two=$(tail -1 file) echo $((f... 阅读全文

posted @ 2016-08-29 13:56 王月波 阅读(3586) 评论(0) 推荐(0) 编辑

shell脚本,检查给出的字符串是否为回文
摘要:[root@localhost wyb]# cat 12321.sh #!/bin/bash #检查给出的字符串是否为回文 read -p "Please input a String:" number [ -z $number ] && echo "input nothing " && exit 1 len=${#number} count=$((len/2)) for i in `... 阅读全文

posted @ 2016-08-29 12:58 王月波 阅读(2040) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示