mngong_rc
asked on
Unix Way to get last months value from this month's date command
This month is October. Would like to have Sept
from the date command
Output of date command
Mon Oct 17 13:58:47 .
Can utilize awk to get oct and was wondering if there is a short way
to get to last months value
Thanks
MNT
from the date command
Output of date command
Mon Oct 17 13:58:47 .
Can utilize awk to get oct and was wondering if there is a short way
to get to last months value
Thanks
MNT
If you don't have GNU date:
#!/bin/bash
typeset -a M=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
echo ${M[$(($(date +%m)-2))]}
Not really elegant ...
#!/bin/bash
typeset -a M=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
echo ${M[$(($(date +%m)-2))]}
Not really elegant ...
... and will not work in January.
So rather try this
#!/bin/bash
typeset -a M=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
N=$(date +%m)
[ $N -eq 1 ] && N=13
echo ${M[$(($N-2))]}
So rather try this
#!/bin/bash
typeset -a M=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
N=$(date +%m)
[ $N -eq 1 ] && N=13
echo ${M[$(($N-2))]}
ASKER
Cannot tell why but this does not run on AIX
#!/usr/bin/bash
typeset -a M=(Jtestdate.ksh[2]: 0403-057 Syntax error at line 2 : `(' is not expected.
Thanks
MNT
#!/usr/bin/bash
typeset -a M=(Jtestdate.ksh[2]: 0403-057 Syntax error at line 2 : `(' is not expected.
Thanks
MNT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found another way out but will be giving points to woolmilkporc
Looks like it should have been beefMilkporc
Thanks
MNT
Looks like it should have been beefMilkporc
Thanks
MNT
date -d "1 month ago" +%B
wmp