Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-07-2007, 03:01 PM
|
#1
|
LQ Newbie
Registered: Oct 2007
Posts: 3
Rep:
|
Case statement with If statement
Basically I am writing a script that will run other scripts.
I want to add an if statement, and I don't know what the best way about that would be. The main script has 5 cases, each case runs 3 different scripts and the last one is simply a quit. Inside each case though I want to add an IF statement that will verify that the user wants to run the scripts, and if the user chooses 'y' or 'Y' then it continues to run the scripts inside that case, and if the user chooses 'n' or 'N' then it quits the script or just returns to the main menu part.
Here is what I have so far, and I'm pretty new to scripting and I can't figure out the best way to incorporate the if statement.
select x in a1 a2 a3 a4 Quit
do
case $x in
a1)...path.../script1.sh
...path.../script2.sh
...path.../script3.sh
break;;
a2)...path.../script4.sh
...path.../script5.sh
...path.../script6.sh
break;;
a3)...path.../script7.sh
...path.../script8.sh
...path.../script9.sh
break;;
a4)...path.../script10.sh
...path.../script11.sh
...path.../script12.sh
break;;
*)break;;
esac
done
Thanks for your help.
Oh, and all the scripts being called inside the case statements, simply run a command.
|
|
|
11-07-2007, 03:49 PM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
I dunno. Sounds like a homework assignment to me.
So, I suggest you read the textbook for the course, the Absolute Bash-scripting Guide, and the Bash Guide for Beginners.
|
|
|
11-07-2007, 04:03 PM
|
#3
|
LQ Newbie
Registered: Oct 2007
Posts: 3
Original Poster
Rep:
|
Not homework. I'm attempting to write a script that will shutdown/stop WebLogic instances. As it is right now we have many instances on many different servers and I am trying to make a weekly process go faster for me. The script will only allow you to choose which combo of instances you want to start up, and then it will auto run the scripts that start them.
a-b)
echo -en "You chose to start a and b, is this correct? "
response="n"
read response
if ["${response}" = y -a "${response}" = Y ]; then
/PATH/startservera.sh
/PATH/startserverb.sh
/PATH/startservere.sh
fi
That is what I currently have in my first case that I want to have in each one. I obviously changed names and stuff though. Basically I have four cases that can start any combo of server abcd where only A or B can be started at one time, and only C or D can be started, and server e starts regardless of which option is chosen.
EDIT:
This is the error I keep getting
./test2.sh: line 11: [y: command not found
Last edited by cbo0485; 11-07-2007 at 04:05 PM.
|
|
|
11-07-2007, 04:24 PM
|
#4
|
LQ Newbie
Registered: Oct 2007
Posts: 3
Original Poster
Rep:
|
Well, I got it through much searching and tweaking and syntax tweaking.
Final IF solution was this:
if [[ "$response" = 'y' || "$response" = 'Y' ]]
I had tried that with only one set of brackets and it didn't work, No idea why a second set made it work.
|
|
|
11-07-2007, 09:05 PM
|
#5
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
You could chop it down abit for the the upper/lower yes part.
For example:
Code:
read -p "You chose to start a and b, is this correct? " response
if [[ "$response" = [yY]* ]]; then
echo "do this"
else
echo "do something else"
fi
|
|
|
All times are GMT -5. The time now is 02:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|