shell - Printing date range in AIX -
i'm trying print date range in aix. i'm not able use 'date' in aix properly. i've tried solutions suggested in stack overflow. nothing worked. please find error , code below. can't download 'gnu'.
#!/bin/ksh startdate=20141030 enddate=20141120 loop_date=$startdate let j=0 while [ "$loop_date" -ne "$enddate" ]; loop_date=`date -j -v+${j}d -f "%y%m%d" "$startdate" +"%y%m%d"` echo $loop_date let j=j+1 done
error: date: illegal option -- j usage: date [-u] [+field descriptors]
try this;
#!/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" ]]; 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" ]]; 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
Comments
Post a Comment