shell script case statement

In a case statement like below :

case $rental in
"car") echo "For $rental Rs.20 per k/m";;
"van") echo "For $rental Rs.10 per k/m";;
"jeep") echo "For $rental Rs.5 per k/m";;
"bicycle") echo "For $rental 20 paisa per k/m";;
*) echo "Sorry, I can not gat a $rental for you";;
esac

I do not want menu to exit unles right option is used , how do i do that ?

-Thanks

while true; do
  cat <<__HERE
Today's menu
  car -- your choice of black or black
  van -- it puts the Jacobson back into van Jacobson compression!
  jeep -- can't think of anything funny here
  bicycle -- at least it beats walking
__HERE
  read rental
  fee=
  case $rental in
    car) fee=Rs.20;;
    van) fee=Rs.10;;
    jeep) fee=Rs.5;;
    bicycle) fee="20 paisa";;
  esac
  case $fee in
    "") echo "Sorry, cannot get a $rental for you"; continue;;
    *) echo "For $rental $fee per k/m"; break;;
  case
done

The refactoring into two separate case statements is not at all necessary, but it makes the script a little bit easier to edit in the future.

menu="Select: car | van | jeep | bicycle"
while :
do
  printf "%s\n: " "$menu"
  read rental
  case $rental in
   "car") echo "For $rental Rs.20 per k/m"; break;;
   "van") echo "For $rental Rs.10 per k/m"; break;;
   "jeep") echo "For $rental Rs.5 per k/m"; break;;
   "bicycle") echo "For $rental 20 paisa per k/m"; break;;
   *) echo "Sorry, I can not get a $rental for you";;
  esac
done

I dont want to exit , it should keep looping in above statement :

After it gives result it should go back to menu ....

Then remove the break statements.

1 Like