Get the last ten business days in a Unix shell script
Shell script to get the last 10 weekdays and run some task for each date over an element array.
#!/usr/bin/bash n=10 today=$(date +'%Y-%m-%d') for ((d=1; n>0; d++)) do # Adjust this next line to get the date format you require, e.g. +'%Y%m%d' date=$(date --date "$today -$d day") nday=$(date --date "$today -$d day" +'%w') weekdays_date=$(date --date "$today -$d day" +'%Y%m%d') if [[ $nday > 0 && $nday < 6 ]] then declare -a arr=("element1" "element2" "element3") # Iterate over the all element for each weekdays_date for el in "${arr[@]}" do echo "Run process for date: ${weekdays_date}, element: ${el}" done # Adjust this next line to output whatever you really need #echo "n=$n, d=$d, nday=$nday, date=$date: WEEKDAY" echo " " : $((n--)) fi done
(Visited 384 times, 15 visits today)