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 } |
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: |
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 } |
All times are GMT -5. The time now is 04:10 PM. |