A simple reworking of the Bash date
command to my own personal liking. Possibly a rather trivial task; I just wanted the date and time to be in the form of:
Fri Sep 2 2016 11:37 P.M.
I think this accomplishes that:
#!/bin/bash
today() {
now="$(date | awk '{ OFS=" "; print $1,$2,$3,$6 }')"
h="$(date "+%H")"
m="$(date "+%M")"
if [ $h -gt 12 ]; then
echo -e "$now\n$(( $h - 12 )):$m P.M."
elif [ $h = 12 ]; then
echo -e "$now\n$h:$m P.M."
elif [ $h = 00 ]; then
h=12; echo -e "$now\n$h:$m A.M."
elif [ $h -le 11 ]; then
if [ $h -lt 10 ]; then
h="$(echo $h | cut -c2)"
fi
echo -e "$now\n$h:$m A.M."
fi
}
today
Is there anything I could do to improve this?