help making loops


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help making loops
# 1  
Old 11-27-2008
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  
Old 11-28-2008
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  
Old 11-28-2008
Hammer & Screwdriver 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  
Old 11-29-2008
Quote:
Originally Posted by hkansal
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help with for loops

Why wont my for statements work? Im trying to get this script to swich to a user an if you put in a start/stop/or restart paramater to do just that for each user. I commented out the actual start/stop actions to test it just by using echos and not do anything hasty in the environment but it... (0 Replies)
Discussion started by: LilyClaro
0 Replies

2. Homework & Coursework Questions

If and Loops

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: In this script you will take a directory as input from the user and change the end of line sequence from a Unix... (1 Reply)
Discussion started by: Pcarson
1 Replies

3. UNIX for Dummies Questions & Answers

Help with for loops

Hi, I am starting to enhance my scripting knowledge and need some assistance with simple 1 line for loops. This may help to do a mass permissions change on a big apache doc root while I have an insane customer on my phone. What is the best resource to learn this skill and what are some that... (5 Replies)
Discussion started by: Oshie74
5 Replies

4. UNIX for Dummies Questions & Answers

loops with tr

Hello, I'm not sure if this is more appropriate for the 'unix for dummies' or the 'unix for experts' forum because I'm new to this forum and this is the second topic I've discussed, but if you could let me know which one was more appropriate for something like this, please do! So in tr (an... (2 Replies)
Discussion started by: juliette salexa
2 Replies

5. UNIX for Dummies Questions & Answers

For Loops

Hi everyone, I have a question regarding for loops. I am writing a BASH shell script that will contain multiple loops. These loops all involve looping with a count: for (( a=0; a <=10; a++ )); do echo $a done If none of my multiple loops relate to each other throughout the script,... (3 Replies)
Discussion started by: msb65
3 Replies

6. Shell Programming and Scripting

Help with the 2 for loops

#!/bin/bash IFS=$'\n' A= a c b t g j i e d B= t y u i o p counter=0 found="" for i in $(cat $A) do for j in $(cat $B) do if then found="yes" fi done if then (1 Reply)
Discussion started by: vadharah
1 Replies

7. UNIX for Dummies Questions & Answers

While Loops

I'm trying to create a loop that will prompt the user for 15 values, not forcing them to enter all 15. If the user enters through one or more of the prompts the null value needs to be converted to 0, otherwise set the parameter = to the value entered: ex. Please enter file no #1: 17920 ... (4 Replies)
Discussion started by: vdc
4 Replies

8. Shell Programming and Scripting

no more loops

Hello Guys I need some help with my script I'm not very good at this, hope you can point me in the right direction. My idea, to write a file with some router commands and use it on a script for me to run on a demand basis, ( or added to the cron, if I get it to work). The below script works,... (5 Replies)
Discussion started by: tony3101
5 Replies

9. Shell Programming and Scripting

loops in loops

ok, i tried to write a script called purge.sh which searches current process' for a specified user running a process with a specified keyword. it also prompts the user to see how many times to purge for the specified process and how many different processes they wish to do this to.it worked until... (11 Replies)
Discussion started by: Blip
11 Replies
Login or Register to Ask a Question

Featured Tech Videos