• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to assign a formatted date to a bash script variable

Resolved: How to assign a formatted date to a bash script variable

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

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.

Answer:

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

If you have better answer, please add a comment about this, thank you!

bash shell
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: When converting markdown to latex with pandoc, how can I end a block before the next heading?

26/03/2023

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.