Not sure I fully understand the logics you tried to put into your script, but it seems there may be a flaw in it:
You have two sequential while loops; in the first you "read" a value into choice and then run a case statement on that variable, break ing out of the loop unless "Go to next menu" is selected. When entering the second loop, choice is never modified; so, if it holds "test" it is in an infinite loop. Any other value will make it break out immediately.
#!/bin/bash
while true; do
choice="$(zenity --width=200 --height=150 --list --column "" --title="test" \
"Go to next menu" \
"test"
"Exit ")"
case "${choice}" in
"Go to next menu" )
while true; do
choice2="$(zenity --width=200 --height=150 --list --column "" --title="test" \
"Do Something" \
"Do Something Else " \
"Back")"
case "${choice2}" in
"Do Something" )
echo "hello"
;;
"Do Something Else " )
echo "hello"
;;
*)
break
;;
esac
done
;;
*)
break
;;
esac
done
case "${choice}" in
"test" )
while true; do
choice3="$(zenity --width=200 --height=150 --list --column "" --title="test" \
"Do Something" \
"Do Something Else " \
"Back")"
case "${choice3}" in
"Do Something" )
echo "hello"
;;
"Do Something Else " )
echo "hello"
;;
*)
break
;;
esac
done
;;
*)
break
;;
esac
done
if i remove the first esac done (the one outisiide the case)the progrmam does not start then if i put it a the end same issue
in this code i the loop only work for "go to menu"
NO. Just one single outer case ... esac .
Just to SEE the logics, try a top-down approach:
while true
do read choice
case $choice in
"go to menu") ... ;;
"test") ... ;;
"exit") ... ;;
*) error handling ;;
esac
done
, then refine/detail each of the menu items. As you can see, proper indenting helps to follow the logics and keeps things together that belong together.
I would suggest that having to rely on break is probably a bad idea. The only place where i think it might be the only solution is within a select loop.
I would suggest that you change your loop from a while true to being based on a condition that is initialised and then changed when you want to leave the loop.
keep_looping=1
while [ $keep_looping -eq 1 ]
do
...
...
...
if [ some condition ]
then
echo "Leaving loop"
keep_looping=0
fi
done
Okay guys thanks for your help but i'm completly lost.
Rudic i tryed this....
#!/bin/bash
while true
do choice="$(zenity --width=200 --height=150 --list --column "" --title="test"
case $choice in
"go to menu") ... ;;
"test") ... ;;
"exit") ... ;;
*) error handling ;;
esac
done
rbatte1 i tryed your code i am able to get the main menu but when i want the sub menu gets complicated . i don't get with the if how to select the variable and apply it
how can i say if [select "go to menu" do .... ]
the code:
#!/bin/bash
keep_looping=1
while [ $keep_looping -eq 1 ]
do choice="$(zenity --width=200 --height=150 --list --column "" --title="test" \
"Go to next menu" \
"test"
"Exit ")"
if [ "${choice}" in
"Go to next menu" )
while true; do
choice2="$(zenity --width=200 --height=150 --list --column "" --title="test" \
"Do Something" \
"Do Something Else " \
"Back")"
done ]
then
echo "Leaving loop"
keep_looping=0
fi
done
When someone posts a problem in these forums, quite a lot of volunteers read it and might want to jump in to help, sometimes giving hints, sometimes pointing out errors, sometimes, if you're lucky, providing an entire working program, eventually even including error handling. The latter shouldn't be expected. And, it can happen only if the situation is absolutely clear, i.e. the requirements are clearly stated, own attempts and representative input data are posted, a desired output is shown, and possible error messages are depicted.
This is not the case with your posts. Unless you give us way more details, I see the help we can give is very general hints only. Like the structural approach models given. You would need to apply some creativity to adapt those to your own problem. If you get stuck, post your attempt and where you're stuck, and we're happy to help out further.
there is no misunderstanding no need to post that much i know how it works.
i post my code wich is working but have a loop issue then you gave me some advice wich i try to apply at best .
then
your colleague gave another way to do it wich i tryed also but has it's not my code anymore i don't know how to use it that's why i ask an "example" related to my code.
I didn't ask to write the code for me but just an example to help me understand
And this kind of answer "Did you REALLY try that pseudo code verbatim?" does not provide help even if it look stupid to you