* [ruby-core:124878] [Ruby Feature#4477] Kernel:exec and backtick (`) don't work for certain system commands
[not found] <redmine.issue-4477.20110307175501.323@ruby-lang.org>
@ 2026-02-24 20:54 ` schneems (Richard Schneeman) via ruby-core
0 siblings, 0 replies; only message in thread
From: schneems (Richard Schneeman) via ruby-core @ 2026-02-24 20:54 UTC (permalink / raw)
To: ruby-core; +Cc: schneems (Richard Schneeman)
Issue #4477 has been updated by schneems (Richard Schneeman).
Just found out about this behavior today when this code
```
out = `command -v ruby`
```
Works on my mac but not on linux (github actions) with an error `Errno::ENOENT: No such file or directory - command`. That is because on my mac `command` is ALSO on the PATH, but on linux it is not. I could fix it by adding a redirect
```
out = `command -v ruby 2>/dev/null`
```
Which triggers the shell behavior.
I find it surprising that exec mentions this behavior https://www.rubydoc.info/stdlib/core/Kernel:exec but backticks https://ruby-doc.org/3.4.1/Kernel.html#method-i-60 doesn't.
----------------------------------------
Feature #4477: Kernel:exec and backtick (`) don't work for certain system commands
https://bugs.ruby-lang.org/issues/4477#change-116537
* Author: JWuttke (Joachim Wuttke)
* Status: Closed
* Assignee: akr (Akira Tanaka)
----------------------------------------
>From documentation and common sense, I would expect that Kernel:exec and backtick (`) work for _all_ kind of system commands. This is currently not the case.
~$ cat test1
echo success
~$ cat test2
#!/bin/sh
echo success
~$ chmod a+x test?
~$ ruby1.8 -e 'p `test1`'
-e:1: command not found: test1
""
~$ ruby1.9 -e 'p `test1`'
-e:1:in ``': Exec format error - test1 (Errno::ENOEXEC)
from -e:1:in `<main>'
~$ ruby1.8 -e 'p `test2`'
"success\n"
~$ ruby1.9 -e 'p `test2`'
"success\n"
This problem has been reported before (#3856: strange Kernel#exec behavior with bash's source command). As a workaround, it has been suggested to append a semikolon to the system command:
~$ ruby1.8 -e 'p `test1;`'
"success\n"
~$ ruby1.9 -e 'p `test1;`'
"success\n"
The report #3856 has been closed with the decision "not a bug".
This I cannot accept. For many years, I got used to run system commands through `<cmd>`. When it failed, I spent painfully long time to search for a bug in my Ruby code and in the system command before I realized the problem was due to an unexpected restriction of Ruby's exec/backtick.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-02-24 20:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-4477.20110307175501.323@ruby-lang.org>
2026-02-24 20:54 ` [ruby-core:124878] [Ruby Feature#4477] Kernel:exec and backtick (`) don't work for certain system commands schneems (Richard Schneeman) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).