-1

I'm trying to automate a script and I need to capture the abbreviated name of the previous month in a variable (e.g. in June, I need the variable to return May). I have the following script, but I'm having trouble assigning it to a variable:

date --date="$(date +%Y-%m-1)-1 month" +%b

Running the above returns 'May'

But mo=date --date="$(date +%Y-%m-1)-1 month" +%b throws this error: -ksh: -ksh: not found [No such file or directory]

Thanks for any help.

jess
  • 3
  • 3

1 Answers1

0

You need command substitution to capture the output of a command:

mo=$(date --date="$(date +%Y-%m-1)-1 month" +%b)
   ~~                                          ~
choroba
  • 231,213
  • 25
  • 204
  • 289