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 显示不同时区的时间

 

上一篇:升级mysql-connector 5到8遇到的问题


下一篇:ubuntu怎么切换到root用户,切换到root账号方法听语音