diff --git a/src/env.c b/src/env.c index 74f50fd..2e60c2e 100644 --- a/src/env.c +++ b/src/env.c @@ -571,13 +571,11 @@ main (int argc, char **argv) case '-': /* Space,tab,dash are undocumented options. Attempt to detect incorrect shebang usage with extraneous space, e.g.: - #!env -v -S'cat -n' - In which case argv[1] == "-v -S'cat -n'" k. - see: https://lists.gnu.org/r/coreutils/2018-04/msg00020.html */ + #!/usr/bin/env -i command + In which case argv[1] == "-i command". */ + error (0, 0, _("invalid option -- '%c'"), optc); if (argc == 3) - error (0, 0, _("possible incorrect usage of env in a script")); - else - error (0, 0, _("invalid option -- '%c'"), optc); + error (0, 0, _("Use -[v]S to pass options in shebang lines")); usage (EXIT_CANCELED); case_GETOPT_HELP_CHAR; @@ -659,5 +657,9 @@ main (int argc, char **argv) int exit_status = errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE; error (0, errno, "%s", quote (argv[optind])); + + if (argc == 3 && exit_status == EXIT_ENOENT && strchr(argv[optind], ' ')) + error (0, 0, _("Use -[v]S to pass options in shebang lines")); + return exit_status; }