LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-16-2002, 10:18 PM   #1
adam_boz
Member
 
Registered: Jul 2002
Location: Santa Cruz, CA
Distribution: lfs
Posts: 538

Rep: Reputation: 30
bash: can't get out of SELECT


I am taking my first stab at writing a bash script. I am writing a script which will install all of the packages in chapter 5 of lfs. I am having problems geting out of the SELECT menue statements (or whatever you guys call them. I made a function called "decompress" which asks if you want your files decompressed, and does it if you do (then moves the orig. files into another folder). Anywase, I can't figure out how to get out of the SELECT statement..... no matter what option i choose, it still brings me back to the menue. I've also tried "exit" after the "if"'s, but that just puts me back to the command line. I have quite a few more functions that i would like to call after "decompress", can anybody help me out? here's decompress:

function decompress {

echo Do you need the files to be decompressed?

OPTIONS="Yes No"

select opt in $OPTIONS; do

if [ "$opt" = "Yes" ]; then
mkdir compressed

for i in $( ls | grep .tar.bz2 );
do
tar -jxvf $i
mv $i compressed/
done

for i in $( ls | grep .bz2 );
do
bunzip2 $i
done

for i in $( ls | grep .tar.gz)
do
tar -zxvf $i
mv $i compressed/
done
clear
echo "All files ending with '.tar.bz2' and '.tar.gz' have been decompressed"
echo " and placed into 'compressed/' folder"
echo
echo " files ending in '.patch.bz2' have been decompressed"

elif [ "$opt" = "No" ]; then
clear
echo MAKE SURE all of your source files are decompressed!!!
echo
echo

else
clear
echo BAD OPTION... Do you want your files decompressed?
fi
done
}
 
Old 09-16-2002, 10:42 PM   #2
gdrobson
Member
 
Registered: Jun 2002
Location: Ontario, Canada
Distribution: RH8.0
Posts: 65

Rep: Reputation: 15
Try using select in the following manner :

select:
select x [in list]
do
commands
done
Korn shell only. Display a list of menu items on standard error, numbered in the order they are specified in list. If no list is given, items are read from the command line (via "$@"). Following the menu is a prompt string (set by PS3). At the PS3 prompt, users select a menu item by typing its line number, or they redisplay the menu by typing RETURN. (User input is stored in the environment variable REPLY.) If a valid line number is typed, commands are executed.

Example

PS3="Select the item number:"
select event in Format Page View Exit
do
case "$event" in
Format) nroff $file | lp;;
Page) pr $file | lp;;
View) cat $file
Exit) exit 0;;
* ) echo "Invalid selection";;
esac
done

The output of this script would look like this:


1. Format
2. Page
3. View
4. Exit
Select the item number:
 
Old 09-16-2002, 11:53 PM   #3
adam_boz
Member
 
Registered: Jul 2002
Location: Santa Cruz, CA
Distribution: lfs
Posts: 538

Original Poster
Rep: Reputation: 30
I guess i just needed to throw in some "break"'s ex:

else
clear
echo BAD OPTION... Do you want your files decompressed?
fi
break
done
}
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 10:35 AM
Select() did not select my socket thvo Programming 1 05-08-2005 12:20 AM
making select show its menu in a bash script? zidane_tribal Programming 6 05-02-2005 05:52 AM
Bash Select Function: Formatting Output mooreted Linux - General 2 03-28-2004 06:26 AM
Bash select statement and spaces meshcurrent Linux - General 2 04-09-2003 09:35 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration