Computing.Net > Forums > Programming > HELP bash script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

HELP bash script

Reply to Message Icon

Name: gera
Date: November 1, 2008 at 13:27:22 Pacific
OS: Linux
CPU/Ram: x86
Product: DELL
Comment:


// 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 in

good)
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 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


// 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,



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 1, 2008 at 21:49:56 Pacific
Reply:

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/bash

echo " ++++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


0

Response Number 2
Name: ghostdog
Date: November 2, 2008 at 01:03:18 Pacific
Reply:

@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.


0

Response Number 3
Name: gera
Date: November 2, 2008 at 08:38:50 Pacific
Reply:

Thanks for your help..


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: HELP bash script

Bash script help www.computing.net/answers/programming/bash-script-help/10720.html

Need Help with Bash script www.computing.net/answers/programming/need-help-with-bash-script/16687.html

Help : Bash script to access all fi www.computing.net/answers/programming/help-bash-script-to-access-all-fi/12080.html