Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Apr 2000 09:55:59 -0700
From:      Doug Barton <Doug@gorean.org>
To:        Greg Pavelcak <gpav@som.umass.edu>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Making sh script pause for input
Message-ID:  <3905CE1F.CAD4A911@gorean.org>
References:  <Pine.OSF.4.10.10004250959270.13917-100000@yolen.oit.umass.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Greg Pavelcak wrote:
> 
> This is driving me nuts. I want a script that prompts with a
> student's name and then waits for input regarding that student
> then moves on. I've tried using xargs and a script like this:

	The bad news, you can't do that with sh because once you tell it to
take its input from a file that's where it's going to take all of its
input from. The good news, this is a really easy perl script, and this
kind of processing is one of the things perl is really good for. 

Good luck,

Doug
-- 
Excess on occasion is exhilarating.  It prevents moderation from
acquiring the deadening effect of a habit.
                -- W. Somerset Maugham


Beware line wrapping

#!/usr/bin/perl -w

open(CONTRACTS, "contractsS00") or die "Can't open contractsS00 for
read: $!";
open(NEW, ">newfile") or die "Can't open newfile for write: $!";

while (<CONTRACTS>)
{
        # Strip the newline off the end of the line
        chomp;

        # Split the input line on whitespace
        ($lognum, $class, $lname, $fname, $gpa, $major) = (split / /);
        print "\n$fname $lname\n";

        print "Status? ";
        chomp($status = <STDIN>);

        print NEW "$lognum  $class  $lname  $fname  $gpa  $major 
$status\n";
}

close CONTRACTS;
close NEW;

print "\nDone\n\n";

exit 0;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3905CE1F.CAD4A911>