Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-07-2007, 02:01 PM   #1
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
case $x in

Thanks for your help.

Oh, and all the scripts being called inside the case statements, simply run a command.
Old 11-07-2007, 02:49 PM   #2
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, 03:03 PM   #3
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.

echo -en "You chose to start a and b, is this correct? "
read response
if ["${response}" = y -a "${response}" = Y ]; then
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.

This is the error I keep getting
./ line 11: [y: command not found

Last edited by cbo0485; 11-07-2007 at 03:05 PM.
Old 11-07-2007, 03:24 PM   #4
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, 08:05 PM   #5
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:
read -p "You chose to start a and b, is this correct? " response

if [[ "$response" = [yY]* ]]; then
   echo "do this"
   echo "do something else"


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 01:19 PM
How do I use an If statement within a case in a Shell script?? crazygyhrous Programming 7 01-03-2006 06:41 AM
problematic case statement alaios Programming 4 08-24-2005 09:05 AM
KSH Scripting case statement..... ']['HeBroken Programming 1 12-10-2004 10:38 AM
bash'ed by case statement??? 3inone Programming 2 04-29-2004 04:52 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:50 AM.

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