Solution for the function in shell

i used "case" functionality to reduce the number of line. if it not proposable let me know i'll give a solution using "if"