get previous month in shell script
✓ Published0🌍 Public
Aadkdev
Last edited Jan 18, 2016
Created on Jan 18, 2016
This shell script calculates the previous month for a given date, storing the result in a text file for later use. It reads a year and month from either command-line arguments or a previously saved file, then uses the GNU `date` command with the `--date` option to subtract one month from the 15th day of the specified month. The script writes the computed year and month back to a file named with a `last_` prefix, enabling sequential month calculations across runs. It relies on Bash parameter expansion for string slicing and file redirection for persistence.
AI-generated description