Shell command in makefile not behaving in nix-shell

In a makefile I am using, there is a variable that’s defined by calling a shell script like so:

VALUE=$(shell mydir/myscript.sh)

The makefile runs correctly if I just execute it in my normal shell (zsh), but when I run the script in a nix-shell environment I get:

make: mydir/myscript.sh: No such file or directory

If I change the execution to this:

VALUE=$(shell sh mydir/myscript.sh)

Than it executes normally. This leads me to believe that this has something to do with one of the environment variables that’s being set by nix-shell automatically. But I can’t seem to narrow down exactly what’s going on. Changing to the sh fix isn’t an option as this is a group project and I’d like to avoid having to change that just for me…plus it feels hacky.

What is the shebang of the file, and what permissions has it set?

@NobbZ, thanks for looking into this. There is no shebang, but it does have 755 permissions on it (-rwxr-xr-x)

Also, it appears I was wrong about the sh modification. I thought that worked but I must have accidentally been running outside of the shell when I ran that in the modified state. I just went and tested it again and it definitely doesn’t work.

  1. If there is no shebang, the current shell might interprete it as is, though make isn’t a shell.
  2. What is the error when it fails with sh?
  1. Adding the shebang fixes it, but this doesn’t really fix my problem as I still can’t check in changes to that file either.
  2. I’m an idiot, when I ran the second test I was calling the wrong makefile…it does actually work. There is no error when specifying a shebang or calling sh directly.

Not using a shebang and relying on make doing the right thing most of the time is not idiomatic. Under no circumstances.

Just fix the shell script to use a shebang with /usr/bin/env bash or whatever shell is actually required.

Yeah, I realize that. Ideally I would be able to modify that section of the code, but the code is owned by another team and is a submodule of what I’m working on.

I was able to figure out that the version of make that the nix shell was using was a newer version (4.2) than the default on my system (3.82). Overriding the package to install the 3.81 version in my shell fixed the issue.

Not saying this is the ideal situation, just that it’s a solution that works for the situation I’m in.

Thanks for the help. @NobbZ

Even if it is a different team, open a ticket with them, or whatever means of communication you use, and tell them, that their project will cause problems with make 4.x and it had cost you some hours to debug. Tell them that the fix is just a single line, that in general makes their script more portable across systems.