I am using getopts for the first time. And I am trying to accept 2 arguments: startyear
and endyear
, based on which the script will continue doing a lot of calculations. But I am not able to make this work.
I am getting blanks for echo variables. What am I doing wrong?
!/bin/bash
while getopts 'hse:' OPTION; do
case "$OPTION" in
h)
echo "h stands for h"
;;
s)
startyear="$OPTARG"
echo "The value provided is $OPTARG"
;;
e)
endyear="$OPTARG"
echo "The value provided is $OPTARG"
;;
?)
echo "script usage: $(basename $0) [-l] [-h] [-a somevalue]" >&2
exit 1
;;
esac
done
shift "$(($OPTIND -1))"
echo "The value provided is $startyear and $endyear"