diff --git a/usr.bin/which/which.1 b/usr.bin/which/which.1 index 9e0c5597025..c00a14ab9fd 100644 --- a/usr.bin/which/which.1 +++ b/usr.bin/which/which.1 @@ -38,8 +38,7 @@ .Sh SYNOPSIS .Nm .Op Fl as -.Op Ar command -.Ar ... +.Ar program ... .Sh DESCRIPTION The .Nm diff --git a/usr.bin/which/which.c b/usr.bin/which/which.c index c3cccfcfc0f..3b8224da43d 100644 --- a/usr.bin/which/which.c +++ b/usr.bin/which/which.c @@ -52,10 +52,6 @@ main(int argc, char **argv) status = EXIT_SUCCESS; - /* If called without args, die silently to conform */ - if (argc < 2) - exit(EXIT_FAILURE); - while ((opt = getopt(argc, argv, "as")) != -1) { switch (opt) { case 'a': @@ -73,6 +69,9 @@ main(int argc, char **argv) argv += optind; argc -= optind; + if (argc == 0) + usage(); + if ((p = getenv("PATH")) == NULL) exit(EXIT_FAILURE); pathlen = strlen(p) + 1; @@ -80,9 +79,6 @@ main(int argc, char **argv) if (path == NULL) err(EXIT_FAILURE, NULL); - if (argc == 0) - status = EXIT_FAILURE; - while (argc > 0) { memcpy(path, p, pathlen); @@ -101,7 +97,8 @@ static void usage(void) { - errx(EXIT_FAILURE, "usage: which [-as] program ..."); + (void)fprintf(stderr, "usage: which [-as] program ...\n"); + exit(EXIT_FAILURE); } static int