Last active
May 3, 2022 17:15
-
-
Save coreymwamba/f0b673056a767a3aa77af698a781d0ce to your computer and use it in GitHub Desktop.
dateutils' ordinal date format doesn't doesn't work; and everyone is still writing things in Python, so... ordinal dates in Shell
This file contains 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/sh | |
today=$(date +'%A %e %B %Y') # obviously you can modify this line | |
D=$(echo $today | grep -E -o "(\b(|[0-3])[0-9]\b)") | |
case $D in | |
1|21|31) | |
mod="st" | |
;; | |
2|22) | |
mod="nd" | |
;; | |
3|23) | |
mod="rd" | |
;; | |
*) | |
mod="th" | |
;; | |
esac | |
ordinal="$D$mod" | |
fulldate=${today/$D/$ordinal} | |
echo ${fulldate/ / } | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment