ok@quintus (07/15/88)
"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?}lwall@devvax.JPL.NASA.GOV (Larry Wall) (07/15/88)
In article <168@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 lwall@jpl-devvax.jpl.nasa.gov
jfh@rpp386.UUCP (John F. Haugh II) (07/16/88)
In article <168@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: jfh@rpp386.uucp | -- with my apologizes