0

以下のコードは bash では機能しますが、ksh では機能しません。現在、コードの下の RHL5 バージョンの OS を使用していますが、正常に動作していますが、sunsolaries では動作していません。サンソラリではコーンシェルを使用しています。

#!/bin/bash
#give start date and enddate in the format yyyy_mm_dd
startdate="${1//_/-}"  # change underscores into dashes
enddate="${2//_/-}"
enddate=`date -d "$enddate + $i day" "+%Y_%m_%d"` #Increases enddate by 1 day so that        loop runs on given enddate also
enddate="${enddate//_/-}"
echo "StartDate: $startdate   EndDate+1Day: $enddate"
nextdate=$startdate #nextdate runs from startdate to enddate
while [ 1 ]
do
    echo "$nextdate $enddate"
if [ "$nextdate" == "$enddate" ];then     #after given enddate loop breaks
    break
fi
day=`date -d "$nextdate"`
arr=(${day// / })
echo "${arr[0]}"
if [ "${arr[0]}" == "Sat" ];then           #checking if day is Saturday, if true then increase nextday  and continue
    nextdate=`date -d "$nextdate + 1 day" "+%Y_%m_%d"`
    nextdate="${nextdate//_/-}"
    continue
fi
#####your code begins here
echo "creating file file_$nextdate.txt"
touch "file_$nextdate.txt" #test code, just creating files with date, remove this
#####your code ends here 
nextdate=`date -d "$nextdate + 1 day" "+%Y_%m_%d"`  #increasing nextday by 1 day
nextdate="${nextdate//_/-}"
done

kshでの仕組みを教えてください

ありがとう

4

1 に答える 1

0

あなたのスクリプトは、Gnu日付固有の-dオプションを数回使用しています。ユースケースでの動作を実現する別の方法を見つけるか、Solaris マシンに Gnu date がインストールされていない場合はインストールしてください。

于 2013-01-21T13:01:13.890 に答える