Java教程

shell脚本实战(第2版)/人民邮电出版社 脚本21 显示不同时区的时间

本文主要是介绍shell脚本实战(第2版)/人民邮电出版社 脚本21 显示不同时区的时间,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
zonedir="/usr/share/zoneinfo/posix"

if [ $# -eq 0 ];then
	timezone="Shanghai"
	mixedzone="Asia"
elif [ "$1" = "list" ];then
	(echo "All known time zones and regions defined on this system:"
         cd $zonedir
         find  -L * -type f -print | xargs -n 2| awk '{printf " %-38s %-38s\n",$1,$2}')|more
	 exit 0
 else
	 region="$(dirname $1)"
	 zone="$(basename $1)"

	 matchcnt="$(find -L $zonedir -name $zone -type f -print | wc -l | sed 's/[^[:digit:]]//g')"

	 if [ "$matchcnt" -gt 0 ];then
		 if [ $matchcnt -gt 1 ];then
			 echo  "\"$zone\" matches more than one possible time zone record. Please usr list to see all known regions and time zones"
                         exit 1
		 fi
		 match="$(find -L $zonedir -name $zone -type f -print)"
		 mixedzone="$zone"
	 else
		 mixedzone="$(echo ${zone%${zone#?}} | tr '[[:lower:]]' '[[:upper:]]')$(echo ${zone#?} | tr '[[:upper:]]' '[[:lower:]]')"

		 if [ "mixedregion" != "." ];then
			 match="$(find -L $zonedir/$mixeregion -type f -name $mixedzone -print)"
		 else
                         match="$(find -L $zonedir -name $mixedzone -type f -print)"
		 fi
		 
		 if [ -z "$match" ];then
                         if [ ! -z $(find -L $zonedir -name $mixedzone -type d -print) ];then
				             echo "The region \"$1\" has more than one time zone."
			             else
				             echo "can't find an exact match for \"$1\"."
			             fi
			 echo "Please ust list to see all known regions and time zones."
			 exit 1
		 fi
	 fi
	 timezone="$match"
fi
nicetz=$(echo $timezone | sed "s|$zonedir/||g")
echo it is $(TZ=$timezone date '+%A ,%B %e,%Y,at %l:%M %p') in $nicetz
exit 0

 

这篇关于shell脚本实战(第2版)/人民邮电出版社 脚本21 显示不同时区的时间的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!