1. Engineering
  2. Computer Science
  3. given the following shell script code snippet that accepts the...

Question: given the following shell script code snippet that accepts the...

Question details

Given the following shell script code snippet that accepts the name of a month and returns which month it is, change it so that it does this with a smaller code size.

read monthname

case $monthname in

## convert $monthname to number

[Jj][Aa][Nn]*) month=1 ;;

[Ff][Ee][Bb]*) month=2 ;; ## ...put the rest of the year here

[Dd][Ee][Cc]*) month=12 ;; [1-9]|1[0-2]) month=$monthname ;;

## accept number if entered *) echo "Invalid month: $monthname" >&2 ;;

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution