下面的代码在 bash 中有效,但在 ksh 中无效。目前我正在使用 RHL5 版本的操作系统,下面的代码工作正常,但在 sunsolaries 中它不工作。在 sunsolaries 中,我们使用 Korn Shell。
#!/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 中工作
谢谢