Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
// My Questions is how can i go back to the selection
after the case *) "bad choice"
in Test_A after bad choice i want to go back to "select TEST_1A in "good" "bad" "EXIT" and run the same in TEST_B after bad choice to go back to select TEST_B2 in "average" "middle" "EXIT"
#!/bin/sh
echo " ++++Plese select the TEST "
select TEST in "TEST_A" "TEST_B"
do
case $TEST in
TEST_A )echo " Please select (1-3) "
select TEST_1A in "good" "bad" "EXIT"
do
case $TEST_1A ingood)
echo " It is good"
exit 0 ;;
bad)
echo " It is bad"
exit 0 ;;
EXIT) exit 0 ;;*)
echo " Bad choise"
break ;;esac
done ;;
TEST_B )echo " Please select (1-3)"
select TEST_B2 in "average" "middle" "EXIT"
do
case $TEST_B2 inaverage)
echo " It is average"
exit 0 ;;
middle)
echo " It is middle"
exit 0 ;;EXIT) exit 0 ;;
*) echo " Bad choise"
break ;;
esac
done ;;
* ) echo " Invalid choice "
exit 0 ;;
esac
done
// My Questions is how can i go back to the selection
after the case *) "bad choise"
in Test_A after bad choise i want to go back to "select TEST_1A in "good" "bad" "EXIT" and run the same in TEST_B after bad choise to go back to select TEST_B2 in "average" "middle" "EXIT"Thanks,

I'm having trouble understanding all of your questions. However, below, I modified the TEST_A select by placing it inside a while loop. Now, an illegal choice forces the TEST_1A select to execute again.
Maybe with this information, you can answer your other questions. Let me know if you have any other questions.
#!/bin/bashecho " ++++Plese select the TEST "
test_a_select=0
select TEST in "TEST_A" "TEST_B"
do
case $TEST in
TEST_A )
echo " Please select (1-3) "
while [ $test_a_select -eq 0 ]
do # inserted while loop
select TEST_1A in "good" "bad" "EXIT"
do
case $TEST_1A in
good)
echo " It is good"
exit 0 ;;
bad)
echo " It is bad"
exit 0 ;;
EXIT) exit 0 ;;
*)
echo " Bad choise"
break ;;
esac
done
done ;;TEST_B )
echo " Please select (1-3)"
select TEST_B2 in "average" "middle" "EXIT"
do
case $TEST_B2 in
average)
echo " It is average"
exit 0 ;;
middle)
echo " It is middle"
exit 0 ;;
EXIT) exit 0 ;;*) echo " Bad choise"
break ;;
esac
done ;;* ) echo " Invalid choice "
exit 0 ;;
esac
done

@OP whenever you need to "go back" to some part of the code, you put loops. Use a while loop and put your selects inside the loop.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |