0

I have a script where i’m trying to get the start date and end date of last 18 months ex. if april is the current month then the return start date should be 2022-10-01 and return end date should be 2022-03-31. I'm pretty new to shell script.

while getopts s:e: dates
do
    case "${dates}" in
        s) startdate=${OPTARG};;
        e) enddate=${OPTARG};;
    esac
done
return_startdate = $(date -d "$startdate -19 months" +%Y-%m-%d);
return_enddate = $(date -d "$enddate -1 day" +%Y-%m-%d);

echo "full_startdate: $startdate";
echo "full_enddate: $enddate";
echo "return_startdate: $return_startdate";
echo "return_enddate: $return_enddate";

The script executed by bash ip_param.sh -s 2022-04-01 -e 2022-04-30'

I tried running in Linux and got this error

ip_param.sh: line 8: return_startdate: command not found
ip_param.sh: line 9: return_enddate: command not found
full_startdate: 2022-04-01
full_enddate: 2022-04-30
return_startdate:
return_enddate:

The Linux I'm using is

NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Sam Gladio
  • 89
  • 1
  • 1
  • 4
  • 1
    `date -d` is a GNU extension and is not avaiable out of the box on MacOS or several other non-Linux platforms. – tripleee May 24 '22 at 11:08
  • See https://stackoverflow.com/questions/3385003/shell-script-to-get-difference-between-two-dates for some portable solutions, though the problem there is slightly different. – tripleee May 24 '22 at 11:16

0 Answers0