I need help with following :-
I have the following function:-
function queuecreate {
echo "1 - Bread"
echo "2 - Milk"
echo "3 - Suger"
echo "4 - Coffee"
echo "What do you need? > "
read QT
case $QT in
1 ) echo "You Chose Bread"
;;
2 ) echo "You Chose Milk"
;;
3 ) echo "You Chose Suger"
;;
4 ) echo "You Chose Coffee"
;;
1 | 4 ) echo "You Chose Bread and Coffee"
;;
* ) echo "You did not enter a number"
echo "between 1 and 4."
esac
Currently the script will print whatever number I input , for example if I input 1 , the
output will be (You Chose Bread) and so on. and if I input 1 and 4 the output will be (You Chose Bread and Coffee)
How can I change it in the way look like this :-
What do you want ?
( ) Bread
( ) Milk
( ) Suger
( ) Coffee
Type yes next to the Iteam you want.
So if the I type yes next to Bread and yes next to coffee
You could use curses to do what you're suggesting, but it would be a lot easier to keep the numbered list you had before and allow the user to enter one or more values in the data you store in the variable QT . The way to efficiently process the returned value would vary depending on the shell you're using.
Here is another way to do this just using standard interfaces:
queuecreate() {
echo "1 - Bread"
echo "10 - Milk"
echo "11 - Suger"
echo "14 - Coffee"
printf 'What do you need? (Enter space separated list of codes): '
read QT
set -- $QT
for choice in "$@"
do case $choice in
(1) echo "You Chose Bread";;
(10) echo "You Chose Milk";;
(11) echo "You Chose Suger";;
(14) echo "You Chose Coffee";;
(*) printf 'Code "%s" is not valid\n' "$choice";;
esac
done
}
while [ 1 ]
do queuecreate
printf 'Try again? (y or n): '
read resp
case $resp in
(N*|n*) exit 0
esac
done
Note that I used 1, 10, 11, and 14 just to get the resulting values into double digits without needing to enter 10 choices. If you want to print a more English like list with commas and an "and" where appropriate, you can easily complicate the logic in the case statement a little bit to make that happen.
Both codes which MadeInGermany and Don Cragun provided are exactly what I wanted . I really appreciated your time and helps.
Also , thank you junior-helper for your time as well, but we are trying to avoid use dialog,