The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed used in loops riayi Shell Programming and Scripting 1 10-01-2008 03:59 AM
Loops mariner UNIX for Advanced & Expert Users 2 07-01-2004 08:50 AM
no more loops tony3101 Shell Programming and Scripting 5 06-09-2004 03:01 PM
loops in loops Blip Shell Programming and Scripting 11 01-20-2004 01:38 PM
While loops bookoo UNIX for Dummies Questions & Answers 5 08-23-2002 12:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-27-2008
afriend afriend is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 7
help making loops

I feel like what I need to do, would be best accomplished with a loop.

However I dont have the slightest idea how to set that up.

The script is part of a interactive shell, for making settings to a Mac OS X server.

This particular part is in regards to disabling files services.


Code:
#!/bin/bash

clear
echo "Turn of Unused File Sharing Services"
echo
PS3='Please enter a choice from the above menu: '


stoplist=`cat <<EOT

AFP
SMB
FTP
NFS

EOT`

turnoffFunction ()
{
select CHOICE in ${stoplist[*]} Quit
do
    case "$CHOICE" in
    "") echo Hit Enter to see menu again!
	continue
	;;
    Quit) break			# exit the loop
    	;;
    *)	serveradmin stop $CHOICE |more
	;;
    esac

}

choiceFunction ()
{
echo -n "Would you like to turn off any more File Sharing Services? [y|n]"
read answer

if [ "$answer" = "y" ]; then
	turnoffFunction
else
	echo `date`
fi
}

turnoffFunction
choiceFunction

I want the user to have to ability to choose all of the choices if thats what they want to do.

The easy way out is just to use the two functions the total number of options available. But if they dont need to disable all the options, then i dont want to force them to go thru more then they have too.

Hopefully that makes since?

And if its not obvious, must of that code I borrowed.
  #2 (permalink)  
Old 11-28-2008
hkansal hkansal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 69
Quote:
I want the user to have to ability to choose all of the choices if thats what they want to do.
If you mean to say that the user must be able to either select an option of his choice or ALL the options.. then you ll need to explicitly show him the option - ALL.

Please let me know if I got you right. Then we may think further.

Regards
  #3 (permalink)  
Old 11-28-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink A loop to prompt for a user action

This will loop and ask for actions until it receives the code (a 9) to stop. There are not any commands to be run, but that could be handled with if or case statements. (You were asking about loops.)


Code:
> cat script82.sh
while [ "$user_rsp" != "9" ]
   do
   echo "###"
   echo "### What to do next ?"
   echo "###"
   echo "### 1 - do this"
   echo "### 2 - do that"
   echo "### 3 - do the other"
   echo "### 9 - all done"
   echo "###"
   read user_rsp
  
   echo $user_rsp

done

  #4 (permalink)  
Old 11-29-2008
afriend afriend is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 7
Quote:
Originally Posted by hkansal View Post
If you mean to say that the user must be able to either select an option of his choice or ALL the options.. then you ll need to explicitly show him the option - ALL.
Thats kinda of right. But i need to to have the ability to pick and choose.

The all choice is good, but I need the user to have the ability to also be able to pick more then just one. And it could be any combination of the options.

Functionally, I guess it would work if it kept asking the user until they chose to quit the command.
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0