Problem with case statement in shell script
I want to select the branch based on the INPUT. Here is the program segment which uses the case statement.
case $INPUT in 1)branch="Computer Science";; 2)branch ="Electrical";; 3)branch = "Mechanical";; 4)branch= "Aerospace";; esac When I run this script, I am getting an error, Electrical command not found? Can anyone help to rectify it? |
Eliminate the white-space characters when assigning values.
Also, post your script code within CODE tags. Something like: Code:
case $INPUT in |
There are two things to mention:
a) you have a blank in the original statement for case 2, but this triggers the bash option to specify one time settings of environement variables like: Code:
$ fubar1=Hello fubar2=world my_binary_or_script b) $INPUT could be empty. I suggest to put it either in quotation marks, or use a default value if it’s unset: ${INPUT:-foobar} and check for the case foobar in the case statement. |
All times are GMT -5. The time now is 12:19 PM. |