Sponsored Content
Top Forums Shell Programming and Scripting basic script for yes and no answers Post 302193098 by denn on Thursday 8th of May 2008 01:25:30 PM
Old 05-08-2008
you was originally going to accept
y|Y|yes) for user input, so users being users, you've really no
idea what they'll type, just for kicks or to give you a hard time.
all the possible options they could use:
yes
YES
YEs
yES
yeS
YeS
yEs

When i give users a choice, I want either a definate positive or a negative,
anthing else is considered invalid and they'll be reasked until they give a proper response.

This is my suggestion:

Code:
#!/usr/bin/ksh

until [[ $answer = "Y" ]] || [[ $answer = "N" ]]
do
        echo "Do you want to start the process 1-5 Y/N?"
        read answer
        answer=`echo $answer | tr [:lower:] [:upper:]`
        case $answer in
           Y|YES)
                answer=`echo $answer | cut -c1`
                # /usr/home/myhome/script.ksh
                print "Process 1-5 Started. Done."
                ;;
           N|NO)
                answer=`echo $answer | cut -c1`
                print "Process 1-5 Not Started. Exiting Now"
                ;;
                
           *)
                print Unexpected Input: $answer  Retrying
                ;;
        esac

done

Note: I commented out your
/usr/home/myhome/script.ksh
to test.

Last edited by denn; 05-08-2008 at 03:51 PM..
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Basic script?

All, I have a list of over 400 users that need certain directories created. These will be created in /users/$username on a system and I need a directory called chess under these directories that I create. Instead of me manually adding each one (mkdir /users/user1, mkdir /users/user1/chess)... (1 Reply)
Discussion started by: kjbaumann
1 Replies

2. Shell Programming and Scripting

I need help with a basic script

a) Total number of words in the file. b) Total number of different words in the file. How can I use the translate and/or unique commands to accomplish this (4 Replies)
Discussion started by: EECSDAVE
4 Replies

3. Shell Programming and Scripting

Shell Script to provide "answers" to SSL Cert Request

Hello, I need assistance with creating a shell script to generate SSL Certificate Requests on remote hosts. Below is my stab at this, but I cannot figure out how to pass the requested arguments into the openssl command correctly. I have a major problem with redirecting the "answers" into the... (2 Replies)
Discussion started by: azvelocat
2 Replies

4. Shell Programming and Scripting

Perl script give answers by file

Hi, I am new in perl. I am running a perl installation script, its asking for paths and so many inputs. Can we provide that info by any file. so i can avoid the interactive installation. (2 Replies)
Discussion started by: Priy
2 Replies

5. Shell Programming and Scripting

Select answers from multiple questions using shell script

I have a text file in this format Some lines.... Question no: 1 The question? A. Answer 1 B. Answer 2 C. Answer 3 D. Answer 4 Answer:B Some lines.... Question no: 2 The question? (choose 2) (10 Replies)
Discussion started by: zorrox
10 Replies

6. Shell Programming and Scripting

Bash script to give multiple choices and a varying number of answers

Hello everybody, I use `case' quite a lot but , excellent as it is , it only gives one final result ; can anyone suggest a way whereas , say long lists of choices are given and I , or a user could select either one two or any number of results to be echoed . many thanks in... (3 Replies)
Discussion started by: V686
3 Replies

7. Shell Programming and Scripting

Need a little help with my first shell script. Basic image resize script...

Hey everyone, just now joined because I didn't want to go onto Ubuntu forums and start asking about how to write shell scripts. Seems like this is a pretty active forum for exactly what I need. I'm trying to modify a shell script I found online, the end goal is to have it find all files in the... (9 Replies)
Discussion started by: mozzles
9 Replies
service(8)						      System Manager's Manual							service(8)

NAME
service - run a System V init script SYNOPSIS
service SCRIPT COMMAND [OPTIONS] service --status-all service --help | -h | --version DESCRIPTION
service runs a System V init script in as predictable an environment as possible, removing most environment variables and with the current working directory set to /. The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of COMMAND depend on the invoked script. service passes COMMAND and OPTIONS to the init script unmodified. All scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart, the script is run twice, first with the stop command, then with the start com- mand. service --status-all runs all init scripts, in alphabetical order, with the status command. EXIT CODES
service calls the init script and returns the status returned by it. FILES
/etc/init.d The directory containing System V init scripts. ENVIRONMENT
LANG, TERM The only environment variables passed to the init scripts. SEE ALSO
/etc/init.d/skeleton, update-rc.d(8), init(8), invoke-rc.d(8). Jan 2006 service(8)
All times are GMT -4. The time now is 05:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy