🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.shell
5 messages
5 total messages Started by Dave Keber Tue, 08 Jan 1991 15:29
Prompting for yes/no in csh
#2312
Author: Dave Keber
Date: Tue, 08 Jan 1991 15:29
11 lines
936 bytes
This may sound like a stupid question to you Unix wizards, but I'm just 
getting started in writing shell scripts and I would like to know:

What is the easiest way to prompt for a yes/no (or any string/number, etc.)
from a csh shell script?

I thought of writing a short C program that asks for input then writing the
answer to standard output, and then calling that program in my shell script,
but that seems a rather convoluted way of going about it...or is it?

Dave
Re: Prompting for yes/no in csh
#2317
Author: Blair P. Houghton
Date: Tue, 08 Jan 1991 16:20
20 lines
1188 bytes
In article <3821@ns-mx.uiowa.edu> dkeber@umaxc.weeg.uiowa.edu (Dave Keber) writes:
>What is the easiest way to prompt for a yes/no (or any string/number, etc.)
>from a csh shell script?

	echo -n "continue? "
	set foo=$<

Salient points:
The -n leaves the cursor on the same line as the prompt; the
quotes allow a space after the prompt; $< reads the script's
standard input up to a newline; and, foo will contain everything
typed, including whitespace, but not the newline.

RTFM for csh(1) and echo(1).  You could have learned all of
this there.  It's the advice of everyone who's ever
answered (or asked) a question on the net that you exhaust
your resources before asking such questions.

				--Blair
				  "Resource your exhaust?"
Re: Prompting for yes/no in csh
#2324
Author: Darin McGrew
Date: Tue, 08 Jan 1991 17:24
25 lines
1319 bytes
dkeber@umaxc.weeg.uiowa.edu (Dave Keber) writes:
>What is the easiest way to prompt for a yes/no (or any string/number, etc.)
>from a csh shell script?

The standard way is to use the pseudo-variable "$<" as follows--

	#!/bin/csh
	echo -n "Really [yn]? "
	set answer = "$<"
	echo "You answered '$answer'"

>I thought of writing a short C program that asks for input then writing the
>answer to standard output, and then calling that program in my shell script,
>but that seems a rather convoluted way of going about it...or is it?

Well, yes, it's convoluted.  But you don't have to write a new
tool to do it this way--

	#!/bin/csh
	echo -n "Really [yn]? "
	set answer = "`head -1`"
	echo "You answered '$answer'"

Darin McGrew			mcgrew@Eng.Sun.COM
Affiliation stated for identification purposes only.
Re: Prompting for yes/no in csh
#2327
Author: Rich Salz
Date: Wed, 09 Jan 1991 15:13
12 lines
871 bytes
In <1991Jan8.204745.16927@informix.com> dberg@informix.com (David I. Berg) writes:
>    echo -n "This is my question. What is your answer? [y/n] (n): "
I have found that
	echo "say what?" | tr -d '\012'
is the most portable way to handle both
	echo -n
and	echo stuff\c

/r$
-- 
Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.
Re: Prompting for yes/no in csh
#2349
Author: Brandon S. Allbery KB8JRR
Date: Fri, 11 Jan 1991 04:10
25 lines
1518 bytes
As quoted from <1660@inews.intel.com> by bhoughto@hopi.intel.com (Blair P. Houghton):
+---------------
| In article <3821@ns-mx.uiowa.edu> dkeber@umaxc.weeg.uiowa.edu (Dave Keber) writes:
| >What is the easiest way to prompt for a yes/no (or any string/number, etc.)
| >from a csh shell script?
| 
| 	echo -n "continue? "
| 	set foo=$<
| 
| RTFM for csh(1) and echo(1).  You could have learned all of
+---------------

The ancient csh's supplied as value-added by most System V vendors do not have
$< --- the manual csh(1) won't help here.  But there is usually a "line"
command that can be used similarly:

	echo "continue? \c"
	set foo="`line`"

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads