现在的位置: 首页 > 综合 > 正文

Shell脚本:时间相关、遍历目录、for、if、字符串比较、数字比较

2018年10月05日 ⁄ 综合 ⁄ 共 349字 ⁄ 字号 评论关闭

时间相关:yesterday、today、tomorrow

#!/bin/sh

Y_DAY=`date -d tomorrow +%Y-%m-%d`" 23:59:00"
Y_TIME=`date -d "$Y_DAY" +%s`

Y_DAYDIR=`date -d yesterday +%Y%m%d`

echo $Y_DAY
echo $Y_TIME
echo $Y_DAYDIR

遍历目录、for、if、字符串比较、数字比较:

查找目录1中存在,目录2中不存在的文件,打印其文件名。

#!/bin/sh

for timefile in `ls $1`
do
	VAR=0
	for dayfile in `ls $2`
	do
		if [ $timefile = $dayfile ]
		then
			VAR=1
		fi
	done
	
	if [ $VAR -eq 0 ]
	then
		echo $timefile 
	fi
done

抱歉!评论已关闭.