Chinaunix首页 | 论坛 | 博客
  • 博客访问: 564446
  • 博文数量: 201
  • 博客积分: 7734
  • 博客等级: 少将
  • 技术积分: 1994
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-09 19:18
文章分类

全部博文(201)

文章存档

2011年(28)

2010年(173)

分类: LINUX

2011-03-29 23:30:36

  1. for #!/bin/bash for i in 1 2 3 4 5 do echo "Welcome $i times" done for i in $( ls ); do echo item: $i done for i in `seq 1 10`; do echo $i done for i in {1..5} do echo "Welcome $i times" done for (( c=1; c<=5; c++ )) do echo "Welcome $c times..." done for i in {0..10..2} do echo "Welcome $i times" done for i in $(seq 1 2 20) do echo "Welcome $i times" done
  2. infinite loops
  3. #!/bin/bash for (( ; ; )) do echo "infinite loops [ hit CTRL+C to stop]" done
  4. find file
  5. #!/bin/bash for file in /etc/* do if [ "${file}" == "/etc/resolv.conf" ] then countNameservers=$(grep -c nameserver /etc/resolv.conf) echo "Total ${countNameservers} nameservers defined in ${file}" break fi done
  6. backup file
  7. #!/bin/bash FILES="$@" for f in $FILES do # if .bak backup file exists, read next file if [ -f ${f}.bak ] then echo "Skiping $f file..." continue # read next file and skip cp command fi # we are hear means no backup file exists, just use cp command to copy file /bin/cp $f $f.bak done
阅读(455) | 评论(0) | 转发(0) |
0

上一篇:bash case

下一篇:bash backup

给主人留下些什么吧!~~