Created
January 19, 2018 18:37
-
-
Save claudinei-daitx/f85687d537813c565038a0dae01c3e80 to your computer and use it in GitHub Desktop.
Get the penultimate Wednesday of the month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
start_date=$1 | |
end_date=$2 | |
current_date= | |
counter=0 | |
index=0 | |
until [ "$current_date" = "$end_date" ] | |
do | |
((counter++)) | |
current_date=$(date -d "$start_date + $counter days" +%Y%m%d) | |
mydate=$(date -d "$start_date + $counter days" +%w) | |
if [ $mydate -eq 3 ] ; then | |
dates[index]=${current_date} | |
((index++)) | |
fi | |
done | |
array_size=${#dates[@]} | |
((array_size--)) | |
((array_size--)) | |
echo ${dates[array_size]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment