standard input to commands in a shell script

Jonathan I. Kamens jik at athena.mit.edu
Mon Oct 15 01:24:41 AEST 1990


In article <BARNETT.90Oct12133123 at grymoire.crd.ge.com>, barnett at grymoire.crd.ge.com (Bruce Barnett) writes:
|> In article <7219 at muffin.cme.nist.gov> libes at cme.nist.gov (Don Libes) writes:
|> >The problem is that ftp (as do most programs) reads passwords from
|> >/dev/tty, ignoring your i/o redirection.  There is no shell mechanism
|> >to get around this. 
|> News to me. I have always done this, which works fine.
|> 
|> set HOST=`hostname`
|> set SOURCE=machine.edu
|> set temp=/tmp/file
|> ftp -n $SOURCE <<END
|> user anonymous $HOST
|> get pub/file $temp
|> quit
|> END

  Don is correct when he says that there is no *shell* mechanism to get around
the problem of a program forcing a read from /dev/tty.

  However, you are correct when you point out that there is an *ftp* mechanism
for getting around the problem of *ftp in particular* forcing a read from
/dev/tty -- just invoke ftp with auto-login disabled (the -n option) and
then supply the password with the "user" command, so that ftp never prompts
for it.

  The other ftp mechanism for getting around the problem is to use a .netrc
files.

  Two other mechanisms for getting around the problem are using Don's "expect"
program (whose use he illustrated in his posting) and using Dan Bernstein's
"pty" program.  Personally, I'd choose pty in this particular case, not
because it's more fault-tolerant than expect (in this case, it isn't), but
rather because the original poster's shell script can be made to work with no
other modifications simply by changing this line:

    ftp genbank.bio.net << END

to this line:

    pty ftp genbank.bio.net << END

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710



More information about the Comp.unix.shell mailing list