https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-06-11T19:51:59ZRuby Issue Tracking SystemRuby master - Feature #16952: Kernel.exec gives an incorrect error message when passed a script with a non-existing shebanghttps://bugs.ruby-lang.org/issues/16952?journal_id=861042020-06-11T19:51:59ZEregon (Benoit Daloze)
<ul></ul><p>I would think this is just the errno you get from <code>execve(2)</code>.<br>
Ruby itself doesn't try to read the shebang.</p>
<p>So not sure Ruby can do much here.<br>
<code>man execve</code> on Linux says:</p>
<blockquote>
<p>ENOENT The file pathname or a script or ELF interpreter does not exist, or a shared library needed for the file or interpreter cannot be found.</p>
</blockquote>
<p>OTOH I think Bash has its own handling and actually reads the shebang (I'm not sure why, and it makes it all more confusing).</p> Ruby master - Feature #16952: Kernel.exec gives an incorrect error message when passed a script with a non-existing shebanghttps://bugs.ruby-lang.org/issues/16952?journal_id=861052020-06-11T20:31:58Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>ruby -v</strong> deleted (<del><i>ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]</i></del>)</li><li><strong>Backport</strong> deleted (<del><i>2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN</i></del>)</li></ul><p>When I run your example in my shell (OpenBSD ksh), I get:</p>
<pre><code>$ ./myscript.rb
ksh: ./myscript.rb: No such file or directory
$ ruby -e 'Kernel.exec("myscript.rb")'
Traceback (most recent call last):
1: from -e:1:in `<main>'
-e:1:in `exec': No such file or directory - myscript.rb (Errno::ENOENT)
</code></pre>
<p><a class="user active user-mention" href="https://bugs.ruby-lang.org/users/772">@Eregon (Benoit Daloze)</a> is correct, examining the shebang appears to be a bash-specific behavior, not a general behavior. So I don't think this qualifies as a bug in Ruby. It could potentially be a useful feature, though.</p> Ruby master - Feature #16952: Kernel.exec gives an incorrect error message when passed a script with a non-existing shebanghttps://bugs.ruby-lang.org/issues/16952?journal_id=861062020-06-11T20:40:17Zdeivid (David RodrÃguez)
<ul></ul><p>In my opinion, the error message I'm being given is a bug, because it's telling me that a file that <em>does</em> exist, doesn't exist. Ruby should double check if the file exists before giving that error message, and if it <em>does</em> exist, give a more generic message that it's not clearly incorrect.</p>