⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 date-calc.sh

📁 Shall高级编程
💻 SH
字号:
#!/bin/bash# date-calc.sh# Author: Nathan Coulter# Used in ABS Guide with permission (thanks!).MPHR=60    # Minutes per hour.HPD=24     # Hours per day.diff () {        printf '%s' $(( $(date -u -d"$TARGET" +%s) -                        $(date -u -d"$CURRENT" +%s)))#                       %d = day of month.}CURRENT=$(date -u -d '2007-09-01 17:30:24' '+%F %T.%N %Z')TARGET=$(date -u -d'2007-12-25 12:30:00' '+%F %T.%N %Z')# %F = full date, %T = %H:%M:%S, %N = nanoseconds, %Z = time zone.printf '\nIn 2007, %s ' \       "$(date -d"$CURRENT +        $(( $(diff) /$MPHR /$MPHR /$HPD / 2 )) days" '+%d %B')" #       %B = name of month                ^ halfwayprintf 'was halfway between %s ' "$(date -d"$CURRENT" '+%d %B')"printf 'and %s\n' "$(date -d"$TARGET" '+%d %B')"printf '\nOn %s at %s, there were\n' \        $(date -u -d"$CURRENT" +%F) $(date -u -d"$CURRENT" +%T)DAYS=$(( $(diff) / $MPHR / $MPHR / $HPD ))CURRENT=$(date -d"$CURRENT +$DAYS days" '+%F %T.%N %Z')HOURS=$(( $(diff) / $MPHR / $MPHR ))CURRENT=$(date -d"$CURRENT +$HOURS hours" '+%F %T.%N %Z')MINUTES=$(( $(diff) / $MPHR ))CURRENT=$(date -d"$CURRENT +$MINUTES minutes" '+%F %T.%N %Z')printf '%s days, %s hours, ' "$DAYS" "$HOURS"printf '%s minutes, and %s seconds ' "$MINUTES" "$(diff)"printf 'until Christmas Dinner!\n\n'#  Exercise:#  --------#  Rewrite the diff () function to accept passed parameters,#+ rather than using global variables.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -