New /usr/bin/env shebang line with version 12.91 breaks with modern coreutils

Started by mceachen, July 24, 2024, 05:43:14 PM

Previous topic - Next topic

mceachen

I'm on Ubuntu 22.04.4 LTS, which includes GNU coreutils version 8.32.

This is running from a local clone of https://github.com/exiftool/exiftool. $ perl exiftool -ver
says 12.91

Any direct invocation that pulls in the shebang line fails, as this version of /usr/bin/env doesn't accept the -w passed to perl in the shebang line.

$ ./exiftool -ver
/usr/bin/env: 'perl -w': No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

$ perl exiftool -ver
12.91

$ head -2 exiftool
#!/usr/bin/env perl -w
#------------------------------------------------------------------------------


The issue is that /usr/bin/env tries to fork "perl -w", rather than the intended "perl" executable with an argument of ["-w"].

Assuming you have a version of coreutils from this decade, the fix for this is to add -S to the shebang:

$ git diff
diff --git a/exiftool b/exiftool
index e00985e5..c9dd1148 100755
--- a/exiftool
+++ b/exiftool
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env -S perl -w
 #------------------------------------------------------------------------------
 # File:         exiftool
 #

Here are the official docs: https://www.gnu.org/software/coreutils/manual/html_node/env-invocation.html#g_t_002dS_002f_002d_002dsplit_002dstring-usage-in-scripts

But I don't think this is the correct fix, because this requires a recent coreutils.
Unfortunately -S is a relatively new addition (geologically speaking):

Ubuntu 18.04's is NOT OK: it uses coreutils version 8.28, which doesn't accept this option. Note that Ubuntu 18 is EOL (and has for a while).

Ubuntu 20.04 is OK: it has coreutils 8.30.

Ubuntu 24.04 is also OK: it has coreutils 9.4

Fedora 34 (from 2021, EOL) is OK: it has coreutils 8.32. Subsequent versions of Fedora are also OK.

macOS Sonoma (v14.5) is OK. I don't have older macOS boxen I can check.

The prior major version of Synology is NOT OK: it's sitting on coreutils version 8.24. I suspect many other NAS/embedded devices have similarly ancient versions of coreutils.

So, this is all kind of a mess (it's frustrating that coreutils would muck with something so basic!)

So, what I'd recommend is:

1. Keep the #!/usr/bin/env perl shebang, but delete the -w argument (rather than using the -S argument to env which requires a mildly recent coreutils).
2. And I think you're done? You already include use warnings and use strict everywhere, so is the -w doing anything?

(FWIW this is the approach I went with for exiftool-vendored.pl)

Thanks again for your continued efforts, Phil!


mceachen


Phil Harvey

OK.  I'll remove the -w.  It applies "use warnings" globally, even for non-exiftool modules.  But it probably isn't helping much.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Neal Krawetz

I was just going to report this same problem.

$ exiftool -g -u -a test.jpg
/usr/bin/env: 'perl -w': No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

Neal Krawetz

12.92 fixed this. Thank you.
(Still doing my long regression test, but this was the first immediate roadblock.)