Path: utzoo!attcan!uunet!lll-winken!lll-tis!mordor!joyce!sri-unix!quintus!ok
From: ok@quintus
Newsgroups: comp.sources.bugs
Subject: Haugh's "env"
Message-ID: <168@quintus.UUCP>
Date: 14 Jul 88 23:35:45 GMT
Sender: n...@quintus.UUCP
Reply-To: ok@quintus ()
Organization: Quintus Computer Systems, Inc.
Lines: 20


"john f. haugh ii" recently sent out public domain code which implements
the System V "env" command.  There are a number of problems:
(1) It uses strchr() rather than index(); if you have an older
    BSD system (why else would you lack "env"?) you probably haven't
    got strchr() either.
(2) main() doesn't end with a call to exit(0); but just falls off the end.
(3) When a command can't be executed, the diagnostic message is
	<command pathname>: <perror text>
    whereas the real "env" command prints
	<perror text>: <command pathname>
    This one's pretty minor.
(4) When a command can't be executed, Haugh's version does _exit(127);
    the status returned by the real env is 1, so change that 127 to 1.
(5) Haugh's version calls
	execve(*argv, argv, env);
    which means that e.g. "env fred=47 sh" doesn't work.  This should be
	extern char **environ;
	environ = env;
	execvp(*argv, argv);
    {Why is there no execvep() library routine?}

Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!elroy!devvax!lwall
From: lw...@devvax.JPL.NASA.GOV (Larry Wall)
Newsgroups: comp.sources.bugs
Subject: Re: Haugh's "env"
Message-ID: <2457@devvax.JPL.NASA.GOV>
Date: 15 Jul 88 07:48:13 GMT
References: <168@quintus.UUCP>
Reply-To: lw...@devvax.JPL.NASA.GOV (Larry Wall)
Organization: Jet Propulsion Laboratory, Pasadena, CA.
Lines: 30

In article <1...@quintus.UUCP> ok@quintus () writes:
: "john f. haugh ii" recently sent out public domain code which implements
: the System V "env" command...

Just for the fun of it, I whipped one off in perl (discovering one perl bug
in the process--this needs patch 9 for reset 'E' to wipe the environment).

Here's env a la perl:

#!/usr/bin/perl

reset 'E', shift if $ARGV[0] eq '-';

$ENV{$1} = $2, shift while $ARGV[0] =~ /(\w+)=(.*)/;

if ($#ARGV < 0) {
    foreach $key (sort keys(ENV)) {
	print $key,'=',$ENV{$key},"\n";
    }
}
else {
    exec @ARGV;
    print $!,': ',shift,"\n";
    exit 1;
}

The only difference I can see is that it sorts the environment variables
when it prints them out.

Larry Wall
lw...@jpl-devvax.jpl.nasa.gov

Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!killer!vector!rpp386!jfh
From: j...@rpp386.UUCP (John F. Haugh II)
Newsgroups: comp.sources.bugs
Subject: Re: Haugh's "env"
Summary: like i said, what do you expect from 30 minutes or so.
Message-ID: <4033@rpp386.UUCP>
Date: 15 Jul 88 22:36:16 GMT
References: <168@quintus.UUCP>
Reply-To: j...@rpp386.UUCP (The Beach Bum)
Organization: Big "D" Home for Wayward Hackers
Lines: 16

In article <1...@quintus.UUCP> ok@quintus () writes:
>
>"john f. haugh ii" recently sent out public domain code which implements
>the System V "env" command.  There are a number of problems:

thanks for the debugging, but as i said in the posting i was actually
waiting for my plexus p/95 to crash when i wrote that.

did anyone else find anything because i kind of like env and i was
going to put mine on my 7th edition box ...

- john.
-- 
John F. Haugh II                 +--------- Cute Chocolate Quote ---------
HASA, "S" Division               | "USENET should not be confused with
UUCP:   killer!rpp386!jfh        |  something that matters, like CHOCOLATE"
DOMAIN: j...@rpp386.uucp          |             -- with my apologizes