Sponsored Content
Full Discussion: ksh prompt yes/no question
Top Forums Shell Programming and Scripting ksh prompt yes/no question Post 302908959 by wisecracker on Saturday 12th of July 2014 04:05:32 AM
Old 07-12-2014
You want to default to YES, although I would personally do it the other way and force the user to enter a 'Y or y'.
However how about using the _wildcard_ '*'...
(On CygWin at the moment and don't have ksh available so using sh instead...)
Code:
#!/bin/sh
echo "is this SQL query ? Y/N"
read  answer
case $answer in
        N|n)
                echo "got a 'no'"
                ;;
        *)
                echo "got a positive answer"
                ;;
esac
exit 0

Results on CygWin...
Code:
AMIGA:~> chmod 755 /tmp/yn.sh
AMIGA:~> cd /tmp
AMIGA:/tmp> dos2unix yn.sh
dos2unix: converting file yn.sh to Unix format ...
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N
slkflksflksldkflskflksjf
got a positive answer
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N

got a positive answer
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N
Y
got a positive answer
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N
y
got a positive answer
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N
N
got a 'no'
AMIGA:/tmp> ./yn.sh
is this SQL query ? Y/N
n
got a 'no'
AMIGA:/tmp> _

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to ask a question to a user in ksh

Hello, I am writing a script in ksh(for HP Unix)where a user must answer to a question . So I want to know kow to test if the user do not answer , so if he enter "REturn". I don't know how to test "space characters" or "empty characters Thanks for your help (2 Replies)
Discussion started by: steiner
2 Replies

2. Shell Programming and Scripting

Question about KSH line.

Wondering what this line meant, especially the 2>&1 and ${RUN_DIR} parts: ${RUN_DIR}/<filename> 2>&1 Where <filename> is the location and name of a file. (1 Reply)
Discussion started by: CapsuleCorpJX
1 Replies

3. Shell Programming and Scripting

ksh question, loops

i want to add about 60 printers using a ksh script. i am having trouble though, i am reading the input from the hosts file and using the lpadmin command to add like so: lpadmin -p -v /dev/null -m netstandard -o dest= i want printername and ipaddy to come from the hosts file, i am having... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

4. Shell Programming and Scripting

A Question On Recursion In Ksh

Hi Folks, I would just like to know how recursion works in ksh or inside a shell in general. I created the following script, but it works(runs recursively) only for 64 times: ---------------- #! /usr/bin/ksh displaymessage() { echo "displaying count: $cnt " echo "wait for 1 second..."... (1 Reply)
Discussion started by: marlonus999
1 Replies

5. UNIX for Dummies Questions & Answers

ksh question

How can I know if my system has ksh feature? #!/usr/bin/ksh Which command we allow me to see? Please advise! (1 Reply)
Discussion started by: bobo
1 Replies

6. Shell Programming and Scripting

ksh if block question

Hi, I am looking at a script, and it contains lines like: if ] ... This is getting me confused. Why do we need $ before (echo $* | egrep -c 'DG')? Why can't we simply have: if ] ... i.e. no $ here before the ()... Thanks. J (3 Replies)
Discussion started by: JamesByars
3 Replies

7. UNIX for Advanced & Expert Users

User friendly Unix ksh prompt to type directories/files

Hello, I wanted to setup user friendly ksh command prompt, by typing first character of files or directories and then tab bring up whole word. No need to type whole file/directory/command names. Example: cat a file like university just typing un and then tab bring up whole university wod.... (3 Replies)
Discussion started by: abdurrouf
3 Replies

8. Solaris

Ok prompt question

I'm new to solaris. Even if the os is not loaded, can we get OK promt via console? (3 Replies)
Discussion started by: mokkan
3 Replies

9. UNIX for Dummies Questions & Answers

How can I show my "current" directory as the KSH prompt?

Hi All, This is an embarrassingly simple question and couldn't think of "keywords" to search for the answer, but how do I change my UNIX/KSH prompt to show the machine name and my "current" but not "full" directory? For example: if the machine name is "machine" and I'm currently in... (4 Replies)
Discussion started by: chatguy
4 Replies

10. UNIX for Dummies Questions & Answers

Question on using a variable in KSH

Hi all, The below command tries to copy ".tgz" instead of "hello_test.tgz" -- It seems as if the underscore gets in the way. I tried with different ways of using quotes, with no luck, unfortunately...it's probably very simple, but may I ask how this would be done: How would the below be... (3 Replies)
Discussion started by: chatguy
3 Replies
suspend(1)                                                         User Commands                                                        suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 11:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy