I've installed mill on arch linux with fish as my default shell. Since the file /usr/bin/mill doesn't start with a shebang, fish won't execute the file. Instead it responds with

$ mill
Failed to execute process '/usr/bin/mill'. Reason:
exec: Exec format error
The file '/usr/bin/mill' is marked as an executable but could not be run by the operating system.

I can execute mill with bash -c 'mill' but I don't want to be doing that all the time. Nor do I want to add that as an alias just for mill. Is it possible to configure fish to always use sh or bash when there isn't a shebang in the script instead of failing? Or maybe there is an operating system level problem?

edit: Mill is just an example. I've encountered this feature of fish numerous times with different scripts that I shouldn't be editing. That's why I'm looking for a way to forever avoid the feature not a one off fix for just mill.

  • It seems to me that the author of the mill software should add an appropriate sh-bang line to it. Initial appearances are that it tries to be a polyglot script, and clearly doesn't support fish. – Jeff Schaller Jul 3 '19 at 17:26
  • Relating: unix.stackexchange.com/q/491419/117549 – Jeff Schaller Jul 3 '19 at 17:27
  • Why don't you want to add an alias? That's exactly what they're for. – glenn jackman Jul 3 '19 at 17:40
  • @glennjackman I've encountered this feature of fish multiple times with files I shouldn't be editing. I don't want to add an alias for every one. I want a permament solution. – cheezsteak Jul 3 '19 at 18:59
  • It's not onerous: alias mill 'bash /usr/bin/mill'; funcsave mill is all it takes. – glenn jackman Jul 3 '19 at 19:25

You can't do that.

You can check its source code:

        execve(actual_cmd, argv, envv);
        err = errno;

        // Something went wrong with execve, check for a ":", and run /bin/sh if encountered. This is a
        // weird predecessor to the shebang that is still sometimes used since it is supported on
        // Windows. OK to not use CLO_EXEC here because this is called after fork and the file is
        // immediately closed.

Notice how its using execve (not execvp or execlp, which have a fall-back to /bin/sh path in case of ENOEXEC) and it will only run the script with /bin/sh if it starts with : (itself quite a dubious feature; especially since fish will also use it in the case of errors other than ENOEXEC).

But if you can edit the script to add a : at the beginning, you can just as well edit it to add a proper she-bang.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.