Fedora Linux Support Community & Resources Center
  #1  
Old 5th November 2004, 12:33 PM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Script - loop

Hi folks,

I have following script as looping. It takes up space.

Script:-
Code:
.... 
# Choosing preset directores for copying
REPLY="B"
until [ -z "$REPLY" ]

do
echo "Choose any of the following:"
echo
echo "[B]123"
echo "[C]123"
echo "[D]123"
echo "[A]ll
echo
echo "[Enter] = Exit"
echo

read

case "$REPLY" in

# Accept upper or lowercase input...
"B" | "b" )
B123
;;

"C" | "c" )
C123
;;

"D" | "d" )
D123
;;

"A" | "a" )
B123
C123
D123
;;

* )
#Default option.
# Do nothing for other keys
;;

esac
done

.....
.....
It has been rearranged in a shorter form to save space as follow;

Script:-
Code:
.... 
....
choices="[B]123 [C]123 [D]123 [A]ll [Enter]=Exit"
echo "Choose one of the following:"
for choice in $choices ; do echo $choice ; done

read reply

case $reply in
[Bb]*) B123 ;;
[Cc]*) C123 ;;
[Dd]*) D123 ;;
[Aa]*) B123 ; C123 ; D123 ;;
*) echo "Exiting..." ; exit ;;
esac
.....
.....
But it is not a loop only running once. Is there any suggestion. TIA

B.R.
satimis
Reply With Quote
  #2  
Old 5th November 2004, 06:16 PM
zjimward Offline
Registered User
 
Join Date: Mar 2004
Location: Tennessee
Posts: 73
Smile

Do the following:

reply="B"
until [ -z "$reply" ]
do

choices="[B]123 [C]123 [D]123 [A]ll [Enter]=Exit"
echo "Choose one of the following:"
for choice in $choices ; do echo $choice ; done

read reply

case $reply in
[Bb]*) B123 ;;
[Cc]*) C123 ;;
[Dd]*) D123 ;;
[Aa]*) B123 ; C123 ; D123 ;;
*) echo "Exiting..." ; exit ;;
esac

done


This will exit if you do not select a valid answer. If you want to stay in the loop when a bad response is given then change:

*) echo "Exiting..." ; exit ;;

to:

"") echo "Exiting..." ; exit ;;

Hope this helps.

Last edited by zjimward; 5th November 2004 at 06:22 PM.
Reply With Quote
  #3  
Old 6th November 2004, 03:32 AM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi zjimward],

Quote:
This will exit if you do not select a valid answer. If you want to stay in the loop when a bad response is given then change:

*) echo "Exiting..." ; exit ;;

to:

"") echo "Exiting..." ; exit ;;
I tried both versions. Script exited finally, instead of continue to next command,

What I expect to do is choosing either 1 or 2 directories rather than either 1 or ALL. Sorry for not explaining clear in my first posting.

B.R.
satimis
Reply With Quote
  #4  
Old 6th November 2004, 05:29 PM
zjimward Offline
Registered User
 
Join Date: Mar 2004
Location: Tennessee
Posts: 73
I'm not real sure I understand exactly what you want to do, but if you want to execute one of the commands in the case...esac and exit then do the following:

reply="B"
until [ -z "$reply" ]
do

choices="[B]123 [C]123 [D]123 [A]ll [Enter]=Exit"
echo "Choose one of the following:"
for choice in $choices ; do echo $choice ; done

read reply

case $reply in
[Bb]*) echo "Bb" ;;
[Cc]*) echo "Cc" ;;
[Dd]*) echo "Dd" ;;
[Aa]*) echo "Aa" ;;
*) echo "Exiting..." ; exit ;;
esac

reply=""

done

You can also re-write the end of the script as follows:

...
until [ -z "$reply" ]
do
...
case $reply in
[Bb]*) echo "Bb" ;;
[Cc]*) echo "Cc" ;;
[Dd]*) echo "Dd" ;;
[Aa]*) echo "Aa" ;;
esac

echo "Exiting..."

break

done

exit

I hope these examples help you.
Reply With Quote
  #5  
Old 8th November 2004, 12:07 PM
satimis Offline
Registered User
 
Join Date: Jul 2004
Posts: 1,398
Hi zjimward,

Tks for your advice.

Quote:
You can also re-write the end of the script as follows:

...
until [ -z "$reply" ]
do
...
case $reply in
[Bb]*) echo "Bb" ;;
[Cc]*) echo "Cc" ;;
[Dd]*) echo "Dd" ;;
[Aa]*) echo "Aa" ;;
esac

echo "Exiting..."

break

done

exit
Just changing following line using "break" to replace "exit" then it works continue to next command.

*) echo "Exiting..." ; exit ;;
replaced with
*) echo "Exiting..." ; break ;;

B.R.
satimis
Reply With Quote
Reply

Tags
loop, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
reboot loop vpg Using Fedora 11 13th February 2008 12:32 AM
sed with loop mystical dervis Programming & Packaging 10 11th July 2007 10:37 AM
AWK in loop pc_catalyst Programming & Packaging 4 9th December 2006 04:52 PM
Loop-Aes help eigen Using Fedora 0 31st May 2004 03:13 PM


Current GMT-time: 10:04 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Bueyuekcekmece Instagram Photos - Lancaster Travel Photos - Yalta