I am trying to figure out the code for this scenario:
Mix your favourite fruit:
1 Apples
2 Pears
3 Plums
4 Peach
5 Pineapple
6 Strawberry
7 All
8 None
Selection:146
Your cocktail will contain: Apples Peach Strawberry
My limited knowledge can do one at time:
echo "Mix your favourite fruit:
1 Apples
2 Pears
3 Plums
4 Peach
5 Pineapple
6 Strawberry
7 All
8 None"
echo Selection:
read selection
case $selection in
1)
mix=Apples
;;
2)
mix=Pears
;;
..
..
12)
mix="Aples Pears"
;;
7)
mix=123456(this is wrong)
;;
8)
mix=no fruits
;;
esac
echo Your cocktail will contain: $mix
I suppose perhaps I could be adding each number entered into array? Then perhaps case esac loop won't be the best solution?
ifcases to handle all possible inputs. Good luck with that. You'd be better off learning how to disect146into individual digits and checking for those only. that'll reduce your code to a split operation + loop, and 8iftests.