LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-07-2007, 03:01 PM   #1
cbo0485
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Rep: Reputation: 0
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.
 
Old 11-07-2007, 03:49 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.
 
Old 11-07-2007, 04:03 PM   #3
cbo0485
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 11-07-2007, 04:24 PM   #4
cbo0485
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
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.
 
Old 11-07-2007, 09:05 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
case statement baks Programming 2 03-15-2007 02:19 PM
How do I use an If statement within a case in a Shell script?? crazygyhrous Programming 7 01-03-2006 07:41 AM
problematic case statement alaios Programming 4 08-24-2005 10:05 AM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 11:38 AM
bash'ed by case statement??? 3inone Programming 2 04-29-2004 05:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration