On 23/04/2024 17:28, Ihor Radchenko wrote:
I propose the attached patch.
+++ b/lisp/ob-shell.el @@ -322,14 +322,12 @@ (defun org-babel-sh-evaluate (session body &optional params stdin cmdline) (with-temp-buffer (with-connection-local-variables (apply #'process-file - (if shebang (file-local-name script-file) - shell-file-name) + shell-file-name stdin-file (current-buffer) nil - (if shebang (when cmdline (list cmdline)) - (list shell-command-switch - (concat (file-local-name script-file) " " cmdline))))) + (list shell-command-switch + (concat (file-local-name script-file) " " cmdline))))
Using `shell-command-switch' unconditionally may lead to executing /bin/sh instead of shell specified by `shell-file-name' for script files having no shebang, see
https://superuser.com/questions/502984/writing-shell-scripts-that-will-run-on-any-shell-using-multiple-shebang-lines
The kernel refuses to execute such scripts and returns ENOEXEC, so the exact behavior depends on the program you run such a script /from/. - bash 4.2.39 -- uses itself - busybox-ash 1.20.2 -- uses itself - dash 0.5.7 -- runs /bin/sh - fish 1.23.1 -- complains about ENOEXEC, then blames the wrong file - AT&T ksh 93u+2012.08.01 -- uses itself - mksh R40f -- runs /bin/sh - pdksh 5.2.14 -- runs /bin/sh - sh-heirloom 050706 -- uses itself - tcsh 6.18.01 -- runs /bin/sh - zsh 5.0.0 -- runs /bin/sh - cmd.exe 5.1.2600 -- looks at you funny
I am not going to spend time testing current versions. I believe, multiple arguments should be specified as '(1 a "b c"). With shebang (as header arg or as part of the body) command should be /path/to/script [ARGUMENT]... when there is no shebang /shell/executable /path/to/script [ARGUMENT]...