dkeber@umaxc.weeg.uiowa.edu (Dave Keber) (01/08/91)
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
bhoughto@hopi.intel.com (Blair P. Houghton) (01/09/91)
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?"
mcgrew@ichthous.Eng.Sun.COM (Darin McGrew) (01/09/91)
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.
rsalz@bbn.com (Rich Salz) (01/09/91)
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.
allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (01/11/91)
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