次のスクリプト:
N=5
BUSINESS_DATE=`date -d "-2 day" +"%Y%m%d"`
for (( c=0; c<N ; c++ ))
do
WEEKDAY=`date --date="$BUSINESS_DATE -$c day" +%w`
if [ $WEEKDAY == "0" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day-2day" +%Y%m%d`;
elif [ $WEEKDAY == "6" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
elif [ $WEEKDAY == "5" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
elif [ $WEEKDAY == "4" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
elif [ $WEEKDAY == "3" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
elif [ $WEEKDAY == "2" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
elif [ $WEEKDAY == "1" ]
then
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day -2day" +%Y%m%d`;
else
FILE_DT_TMP=`date --date="$BUSINESS_DATE -$c day" +%Y%m%d`
fi
export FILE_DT=$FILE_DT_TMP
echo "File date is :$FILE_DT"
done
正しい出力を提供しません。誰でも私に教えてもらえますか?何が間違っていて、どのように解決できますか?
ベストアンサー1
今日から営業日基準の5日前にのみ試してみたい場合は、次の手順に従ってください。
for d in Mon Tue Wed Thu Fri
do
date +%Y%m%d -d "last $d"
done | sort
今日の前のN日間:
N=10
for i in $(seq $(($N + $N / 5 * 2)) -1 1)
do
[ `date --date="-$i day" +%u` -le 5 ] &&
date -d "-$i day" +"File date is : %Y%m%d"
done