Lab : Conditional Logic Q4

====================================

In Lab of Conditional Logic Q4 . I have developed the script to meet the expected results . I have checked it’s output for months 1 to 12 and also blank input and any month outside this range ( other than 1 to 12 ) . I can see it works as expected but it does not passes in the checks.

Can you please review and test this script and let me know what is the issue in below script ?
Why this is not getting passed ?

Q4 :
Develop a shell script /home/bob/print-month-name.sh that accepts the number of a month as input and prints the name of the respective month. eg ./print-month-name.sh 1 should print January and ./print-month-name.sh 5 should print May . Also keep these in mind.

  1. The script must accept a month number as a command line argument.
  2. If a month number is not provided as command line argument, the script must exit with the message No month number given .
  3. The script must not accept a value other than 1 to 12 . If not the script must exit with the error Invalid month number given .
  • Tasks not completed!

  • Script runs as expected.

  • Script prints “No month number given” if no month number is given.

  • Script prints “Invalid month number given” if month number is not 1 to 12.


I have checked below script and as per my checks it provides output as expected . 
Can you please check and revert what is issue with the below script and why it is failing in checks ?

bob@caleston-lp10:~$ ls -al
total 84
drwxr-xr-x 1 bob  bob  4096 Nov 29 09:59 .
drwxr-xr-x 1 root root 4096 Apr 14  2020 ..
drwxrwxr-x 2 bob  bob  4096 Apr 27  2020 .aws
-rw------- 1 bob  bob  2571 May 23  2020 .bash_history
-rw-r--r-- 1 bob  bob    70 Nov 29 09:01 .bashrc
drwx------ 3 bob  bob  4096 Apr 27  2020 .cache
drwx------ 3 bob  bob  4096 Apr 21  2020 .gnupg
drwx------ 4 bob  bob  4096 Apr 27  2020 .local
-rw-rw-r-- 8 bob  bob   135 Apr 27  2020 .profile
drwx------ 2 bob  bob  4096 Apr 15  2020 .ssh
-rw------- 8 bob  bob  7838 Apr 27  2020 .viminfo
-rw-r--r-- 1 bob  bob    75 Nov 29 09:00 .vimrc
-rw-r--r-- 1 bob  bob   598 Nov 29 09:59 1
drwxr-xr-x 2 bob  bob  4096 Nov 29 09:04 chandamama-mission
-rwxr-xr-x 1 bob  bob    93 Nov 29 09:09 check_dir.sh
-rwxr-xr-x 1 bob  bob   103 Nov 29 09:18 check_greater.sh
-rwxr-xr-x 1 bob  bob   396 Nov 29 09:06 create-and-launch-rocket
-rwxr-xr-x 1 bob  bob   598 Nov 29 09:59 print-month-name
bob@caleston-lp10:~$
bob@caleston-lp10:~$ cat print-month-name
A=$1

if [[ -z $A ]]
 then echo "No month number given"
elif [[ $A -lt 1 || $A -gt 12 ]]
 then echo "Invalid month no given"
 exit
fi

if [[ $A = 1 ]]
 then echo "January"
elif [[ $A = 2 ]]
 then echo "February"
elif [[ $A = 3 ]]
 then echo "March"
elif [[ $A = 4 ]]
 then echo "April"
elif [[ $A = 5 ]]
 then echo "May"
elif [[ $A = 6 ]]
 then echo "June"
elif [[ $A = 7 ]]
 then echo "July"
elif [[ $A = 8 ]]
 then echo "August"
elif [[ $A = 9 ]]
 then echo "September"
elif [[ $A = 10 ]]
 then echo "October"
elif [[ $A = 11 ]]
 then echo "November"
elif [[ $A = 12 ]]
 then echo "December"
fi

bob@caleston-lp10:~$

bob@caleston-lp10:~$
bob@caleston-lp10:~$ bash print-month-name
No month number given
bob@caleston-lp10:~$
bob@caleston-lp10:~$ bash print-month-name 1
January
bob@caleston-lp10:~$ bash print-month-name 2
February
bob@caleston-lp10:~$ bash print-month-name 3
March
bob@caleston-lp10:~$ bash print-month-name 4
April
bob@caleston-lp10:~$ bash print-month-name 5
May
bob@caleston-lp10:~$ bash print-month-name 6
June
bob@caleston-lp10:~$ bash print-month-name 7
July
bob@caleston-lp10:~$ bash print-month-name 8
August
bob@caleston-lp10:~$ bash print-month-name 9
September
bob@caleston-lp10:~$ bash print-month-name 10
October
bob@caleston-lp10:~$ bash print-month-name 11
November
bob@caleston-lp10:~$ bash print-month-name 12
December
bob@caleston-lp10:~$ bash print-month-name 113
Invalid month no given
bob@caleston-lp10:~$ bash print-month-name 13
Invalid month no given
bob@caleston-lp10:~$
bob@caleston-lp10:~$ bash print-month-name 13-56
Invalid month no given
bob@caleston-lp10:~$ bash print-month-name -456
Invalid month no given
bob@caleston-lp10:~$ bash print-month-name
No month number given
bob@caleston-lp10:~$ pwd
/home/bob
bob@caleston-lp10:~$

Check this one as well if it helps.

if [[ -z $1 ]]

then

echo "No month number given"

elif [[ $1 -lt 1 || $1 -gt 12 ]]

then

echo "Invalid month number given"

elif [[ -n $1 && $1 -lt 13 ]]

then

 cal -m $1 | awk 'NR==1 {print $1}'

fi