Hacker News new | ask | show | jobs
by asveikau 2225 days ago
I can see two areas in which it might break.

I might put #!/usr/bin/env make -f in case it's somewhere in else in PATH.

Also some systems (BSD, old commercial Unix) have non-gnu-compatible make and sometimes call their gnu make port "gmake" or "gnumake".

2 comments

AFAIR on Linux shebangs only support single argument so it would fail in this case. One can overcome this treating the file as a shell script:

  #!/bin/sh
  # make ignores next line \
  set -e
  # make ignores next line \
  exec make -f "$0" "$@"
Make treats slash-escaped new lines as a continuation even for comments, shell does not.
Wow. Impressive.
That shebang is appealing but unfortunately more than one argument (past the initial command name) in a shebang is unportable: some OSes will coalesce the extra arguments into one, others make them separate arguments.

There's also a special bonus papercut you might hit when /usr/bin/env is in the shebang with extra arguments: an infinite loop!

Sorry for the plug: I wrote about it here. https://www.crystae.net/posts/2019/11/08/two-shebang-papercu...

GNU coreutils env supports a flag for it since 8.30 which translates to Debian 10 & Ubuntu 19.04. Not a perfect solution, but it appears to allow portability across the vast majority of modern OSes?