Browse Source

ob-shell: honor the specified shell for :session

* lisp/ob-shell.el: Remove defcustom `org-babel-sh-command' and
  replace with `shell-file-name' throughout.
  (org-babel-variable-assignments:sh): Make check for bash work in more

The original code and the patched version rely on the shell being
available via PATH.  Instead the shell name should be mapped to the
appropriate executable via an alist and invoked via an absolute
filename.  For security reasons the permissible shells should probably
be taken from /etc/shells or equivalent by default.  Instead of
checking for bash, the same or another alist could provide the
information of whether or not the shell supports arrays (which indeed
were introduced by ksh originally).
Achim Gratz 3 years ago
1 changed files with 4 additions and 11 deletions
  1. 4 11

+ 4 - 11

@@ -38,13 +38,6 @@
 (defvar org-babel-default-header-args:sh '())
-(defcustom org-babel-sh-command shell-file-name
-  "Command used to invoke a shell.
-Set by default to the value of `shell-file-name'.  This will be
-passed to `shell-command-on-region'"
-  :group 'org-babel
-  :type 'string)
 (defcustom org-babel-shell-names
   '("sh" "bash" "csh" "ash" "dash" "ksh" "mksh" "posh")
   "List of names of shell supported by babel shell code blocks."
@@ -57,7 +50,7 @@ passed to `shell-command-on-region'"
      (lambda (name)
        (eval `(defun ,(intern (concat "org-babel-execute:" name)) (body params)
 		,(format "Execute a block of %s commands with Babel." name)
-		(let ((org-babel-sh-command ,name))
+		(let ((shell-file-name ,name))
 		  (org-babel-execute:shell body params)))))
      (second value))))
@@ -144,7 +137,7 @@ This function is called by `org-babel-execute-src-block'."
      (lambda (pair)
-       (if (string= org-babel-sh-command "bash")
+       (if (string-match "bash$" shell-file-name)
             (car pair) (cdr pair) sep hline)
@@ -211,7 +204,7 @@ return the value of the last statement in BODY."
                 (if shebang
-                  (format "%s %s" org-babel-sh-command script-file))
+                  (format "%s %s" shell-file-name script-file))
                 (current-buffer) nil cmdline)
@@ -249,7 +242,7 @@ return the value of the last statement in BODY."
                    (insert body))
                  (set-file-modes script-file #o755)
                  (org-babel-eval script-file ""))
-             (org-babel-eval org-babel-sh-command (org-babel-trim body)))))))
+             (org-babel-eval shell-file-name (org-babel-trim body)))))))
     (when results
       (let ((result-params (cdr (assoc :result-params params))))
         (org-babel-result-cond result-params