【问题标题】:Printing date range in AIX在 AIX 中打印日期范围
【发布时间】:2016-11-29 00:05:36
【问题描述】:

我正在尝试在 AIX 中打印日期范围。我无法在 AIX 中正确使用“日期”。我已经尝试了堆栈溢出中建议的一些解决方案。没有任何效果。请在下面找到错误和代码。 我无法下载“GNU”。

#!/bin/ksh
startdate=20141030
enddate=20141120

loop_date=$startdate

let j=0
while [ "$loop_date" -ne "$enddate" ]; do
        loop_date=`date   -j -v+${j}d  -f "%Y%m%d" "$startdate" +"%Y%m%d"`
        echo $loop_date
        let j=j+1
done

错误: 日期:非法选项--j 用法:日期 [-u] [+字段描述符]

【问题讨论】:

  • 你为什么认为有-j 选项?
  • 感谢您查看此内容。当我进行更多调查时。我发现,除了 AIX 中的“-n”、“-u”或“-a”(man date),我不应该使用任何选项。我想知道有没有其他方法可以打印日期范围。我试图包含 perl,得到以下错误。 -- 在@INC 中找不到 Time/Piece.pm(@INC 包含。
  • 我在 AIX 中发现了类似的问题,但没有解决方案。 Click here
  • 如果你没有 gawk,你没有 perl,你没有 Python,你不能用 C 编译一个新写的软件,你不用这里没有很多选择。我的意思是,有些工具 POSIX 规范还不够完整,无法涵盖,所以有时您需要基线工具包中没有的工具。
  • 不少人能够下载 GNU!coreutils,我不知道为什么 OP 不能这样做......

标签: shell date ksh aix


【解决方案1】:

试试这个;

#!/bin/ksh
startdate=$1
enddate=$2
loop_date=$startdate
currentdate=`date +%Y%m%d`

let j=0;

if [[ $startdate -lt $currentdate && $enddate -lt $currentdate ]];then
loop_date=$currentdate
while [[ "$loop_date" -gt "$startdate" ]]; do
loop_date=$(TZ=CST+$j date +%Y%m%d)
   if [[ $loop_date -le $enddate ]];then
      echo $loop_date
   fi
let j=j+24
done
fi

if [[ $startdate -gt $currentdate && $enddate -gt $currentdate ]];then
while [[ "$loop_date" -lt "$enddate" ]]; do
loop_date=$(TZ=CST-$j date +%Y%m%d)
   if [[ $startdate -le $loop_date ]];then
      echo $loop_date
   fi
let j=j+24
done
fi


user@host:/tmp:>ksh test.sh 20150630 20150705 
20150705
20150704
20150703
20150702
20150701
20150630
user@host:/tmp:>ksh test.sh 20170630 20170705 
20170630
20170701
20170702
20170703
20170704
20170705

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2017-05-16
    • 2014-01-07
    相关资源
    最近更新 更多