0

I want to get the name of the previous month to define it as a variable in my shell script. I tried different commands available on the internet, but doesn't seem working, like:

TZ=CST+24 date +%b gives me output as Aprand date -d "last month" '+%Y%m' gives the output as :

date: illegal option -- d Usage: date [-u] [+format] date [-u] [mmddhhmm[[cc]yy]] date [-a [-]sss.fff]

My expected output is Mar or March

User123
  • 1,498
  • 2
  • 12
  • 26

1 Answers1

0

EDIT: Question has been updated to show that the -d option is invalid in HP-UX's date.

Consider looking at getting past dates in HP-UX with ksh for some ideas.


How about:

$ date -d 'last month'
Fri Mar 23 14:16:13 CDT 2018

$ date -d 'last month'
Fri Mar 23 14:16:15 CDT 2018

$ date -d 'last month' '+%b'
Mar
markp-fuso
  • 28,790
  • 4
  • 16
  • 36