shell中日期循环的方式

第一种

# 这里的例子以周为循环
!/bin/bash

begin_date="20160907"
end_date="20170226"

while [ "$begin_date" -le "$end_date" ];
do
    year=${begin_date:0:4}
    week_of_year=$(date -d "$begin_date" +%W)
    echo $year, $week_of_year
    begin_date=$(date -d "${begin_date}+7days" +%Y%m%d)
done

第二种

# 这里的例子每天作为循环,并展示当天的前一天
#!/bin/bash

startDate=20160201
endDate=20160328
startSec=`date -d "$startDate" "+%s"`
endSec=`date -d "$endDate" "+%s"`
for((i=$startSec;i<=$endSec;i+=86400))
do
    current_day=`date -d "@$i" "+%Y%m%d"`
    one_day_ago=`date -d "$current_day yesterday" +%Y%m%d`
    echo "current_day:${current_day}, yesterday:${one_day_ago}"
done
时间: 2024-08-24 15:48:40

shell中日期循环的方式的相关文章

shell中for循环总结

关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿... 1. for((i=1;i<=10;i++));do echo $(expr $i \* 4);done2.在shell中常用的是 for i in $(seq 10)3.for i in `ls` 4.for i in ${arr[@]}5.for i in $* ; do6.for File in /proc/sys/net/ipv4/confacc

Shell中的循环语句实例

1.for循环语句实例1.1 最基本的for循环 #!/bin/bash for x in one two three four do     echo number $x done 注:"for" 循环总是接收 "in" 语句之后的某种类型的字列表.在本例中,指定了四个英语单词,但是字列表也可以引用磁盘上的文件,甚至文件通配符.实例1.2 #!/bin/bash for x in /var/log/* do     #echo "$x is a file

shell中for循环

关于shell中的for循环用法很多,一直想总结一下,今天网上看到上一篇关于for循环用法的总结,感觉很全面,所以就转过来研究研究,嘿嘿... 1. for((i=1;i<=10;i++));do echo $(expr $i \* 4);done2.在shell中常用的是 for i in $(seq 10)3.for i in `ls` 4.for i in ${arr[@]}5.for i in $* ; do6.for File in /proc/sys/net/ipv4/confacc

shell中while循环引用ssh命令的坑

原理shell代码如下: #!/bin/sh cat ../androidsrc | while read line do         ip=$(echo $line | awk '{print $1}')         srcdir=$(echo $line | awk '{print $2}')         destdir=$(echo $line | awk '{print $3}')         user=$(echo $line | awk '{print $4}')  

(八)shell中的循环结构

1.for循环(1)要求:能看懂.能改即可.不要求能够完全不参考写出来.因为毕竟嵌入式并不需要完全重新手写shell,系统管理员(服务器运维人员,应用层系统级管理开发的才需要完全掌握shell) 这里将1 2 3 4 5依次打印出来 打印出当前目录文件 2.while循环(1)和C语言的循环在逻辑上无差别(2)要注意很多格式要求,譬如:while后面的[]两边都有空格,[]后面有分号分号(如果do放在一行的话),i++的写法中有两层括号. 3.echo的创建和追加输入文件(1)在shell中可以

在shell中运行以不同方式运行脚本

在shell当中,可以有3中方式运行脚本: 1 . ./script_name 或者source ./script_name 2 直接./script_name 3 ./script_name & 加入脚本script_name中有两个命令command1,command2,那么,当以第一种方式运行时,command1和command2都在当前shell中运行,并没有产生subshell,如下图所示: 当script_name以第2中方式运行时,当前shell会产生一个subshell,comm

shell中的循环语句

for语法格式 for var in list;do commands done 其中list可以包含: 1) 直接写 for alpha in a b c d;do echo $alpha done 2)变量 list="a b c d" for alpha in $list;do echo $alpha done 在shell执行的时候会进行变量替换,上面的list变量替换之后,for循环的形式和1中的形式一模一样.但是如果为$list加上了引号,即如果写为下面的形式: list=

Shell中while循环的done 后接一个重定向&lt;

转自:http://hi.baidu.com/%CE%D2%D2%AA_%D1%A7_%CF%B0/blog/item/b3b5e723bb2ed1265243c1e4.html 读文件的方法: 第一步: 将文件的内容通过管道(|)或重定向(<)的方式传给while 第二步: while中调用read将文件内容一行一行的读出来,并付值给read后跟随的变量.变量中就保存了当前行中的内容. 例如读取文件/sites/linuxpig.com.txt 1)管道的方式:      cat /sites

javascript中数组循环的方式

forEach循环:        arr1.forEach(function(value,i)//value 值 i 下标            {console.log([value,i])});for in 循环:         for(var k in arr1){                arr2[k]=arr1[k]*10;//k为下标            } map方法:        //循环数组 创建新数组 全部        var arr3=arr1.map(fu