== Bash's superintelligent errors about exec failures Let's take a closer look at bash's error message from [[yesterday ../linux/BashNoInterpreterMsg]], because if you pay close attention something really interesting is going on. Here's the error message again: > _bash: /tmp/exmpl: /bin/shx: bad interpreter: No such file or directory_ On first blush, if you don't think about it too much, this looks perfectly sensible: bash is reporting that when it tried to _exec()_ the _/tmp/exmpl_, the kernel told it that there was a problem with the script's interpreter. But, wait. When the _exec()_ fails, all that kernel can tell bash is the _errno_ number. In this case the kernel returns _ENOENT_, which creates the 'No such file or directory' portion of the error message. So how does bash know that the reason that trying to run _/tmp/exmpl_ failed is because _/bin/shx_ doesn't exist? Here, have another example error message from bash: > _bash: /tmp/a.out: /lib64/ld-ZZZZZ-x86-64.so.2: bad ELF interpreter: > No such file or directory_ (I did some binary editing to create that failure.) That's right. When an _exec()_ fails, ~~bash opens the executable and parses it to try to identify what went wrong~~. It recognizes shell scripts, which is easy, but it also parses ELF binaries to find things like the name of the ELF interpreter, so it can check that. Let me say that again: ~~bash knows how to parse ELF binaries so that it can give you good error messages~~. I must applaud bash's attempt to be almost as user friendly as possible, but at the same time I think it went more than a little bit overboard. (If you trace the system calls it's using, you can clearly see it selectively reading several bits of the ELF binary.) If you try these same things in other, simpler shells, they will simply report something like '_/tmp/exmpl: No such file or directory_', ie they are simply doing a straightforward translation of what the kernel told them (even if it is a rather puzzling message). (zsh will report the interpreter problem with a shell script but not with a binary, which strikes me as a reasonable amount for a complex shell to do. Checking for this error with shell scripts is not that difficult and it does happen periodically.)