title: Why do sh, zsh, and bash return zero when executing a zero byte file?
body: <p>Why can you can execute an empty file in bash, zsh, or sh and it will exit code 0 when an execve syscall with an empty file will exit ENOEXEC? </p>
  
  <pre><code>touch zero
  chmod +x zero
  ./zero
  echo $?
  </code></pre>
  
  <pre><code>0
  </code></pre>
  
  <p><code>execve</code> exit's -1 with <code>ENOEXEC Exec format error</code> so it isn't an operating systems behavior.</p>
  
  <pre><code>strace -f ./zero
  execve("./zero", ["./zero"], [/* 53 vars */]) = -1 ENOEXEC (Exec format error)
  write(2, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
  ) = 32
  exit_group(1)                           = ?
  +++ exited with 1 +++
  </code></pre>
  
  <p>sh also calls execve and gets -ENOEXEC but it proceeds to read 80 bytes of the file and exit zero.</p>
  
  <pre><code>strace -f sh -c "./zero"
  ...
  execve("./zero", ["./zero"], [/* 52 vars */]) = -1 ENOEXEC (Exec format error)
  open("./zero", O_RDONLY)                = 3
  read(3, "", 80)                         = 0
  close(3)                                = 0
  exit_group(0)        
  </code></pre>