if there is no argument i can generate the current month and year(012021) and lastmonth(122020) with "-d 'last month'" option. if I entered argument like "01/01/2019" i can handle $currentmonth(012019) but not $pastmonth variable. is there any way to solve this.
#!/bin/bash
if [ -z "$1" ] ;then
currentmonth=`date "+%m%Y"`
pastmonth=`date "+%m%Y" -d 'last month'`
echo $currentmonth
echo $pastmonth
else
currentmonth=`date +%m%Y --date="$1"`
pastmonth=?
echo $currentmonth
echo $pastmonth
fi