Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • That's very good answer! :) I can accept it but can't give a "plus", because i have no privileges to do so yet (I will never understand why they do that here...) I asked this on serverfault because i was trying to figure out if one could use env to circumvent non default installs, but that show I can't do that way. Need to think more. Commented Feb 20, 2017 at 5:43
  • @flavio use /bin/sh as the shebang, then at the start of the script, try to locate bash (or whatever it is you'd do with env) and use bash to run the script. Commented Feb 20, 2017 at 5:45
  • That's arguably a bug in zsh. Bash and zsh both try to emulate the #! mechanism (in case they're running on some exotic system that doesn't support shebangs). Bash does it faithfully. Zsh performs a PATH lookup for the shebang program, which in principle is helpful but has the downside of being a zsh-specific thing. Commented Feb 21, 2017 at 1:26
  • Note that the part of your answer about execlp and execvp running scripts with sh does not apply here. It would apply if 1. the caller was calling one of these functions rather than some other wrapper for the execve system call, and 2. the execve call returned ENOEXEC. But here execve doesn't return ENOEXEC, because foo.sh does have a valid format — it starts with a shebang. The kernel tries to execute env and that fails with ENOENT because there's no file called env. Commented Feb 21, 2017 at 1:29
  • @Gilles hmm, I though valid format meant something like ELF or a.out, since it doesn't say an interpreter script is a valid format for execve. Commented Feb 21, 2017 at 1:49