Function: eshell-find-interpreter
eshell-find-interpreter is a byte-compiled function defined in
esh-ext.el.gz.
Signature
(eshell-find-interpreter FILE ARGS &optional NO-EXAMINE-P)
Documentation
Find the command interpreter with which to execute FILE.
If NO-EXAMINE-P is non-nil, FILE will not be inspected for a script line of the form #!<interp>.
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/esh-ext.el.gz
(defun eshell-find-interpreter (file args &optional no-examine-p)
"Find the command interpreter with which to execute FILE.
If NO-EXAMINE-P is non-nil, FILE will not be inspected for a script
line of the form #!<interp>."
(let ((finterp
(catch 'found
(ignore
(dolist (possible eshell-interpreter-alist)
(cond
((functionp (car possible))
(let ((fn (car possible)))
(and (funcall fn file args)
(throw 'found (cdr possible)))))
((stringp (car possible))
(and (string-match (car possible) file)
(throw 'found (cdr possible))))
(t
(error "Invalid interpreter-alist test"))))))))
(if finterp ; first check
(list finterp file)
(let ((fullname (if (file-name-directory file) file
(eshell-search-path file)))
(suffixes eshell-binary-suffixes))
(when (and fullname
(not (file-remote-p fullname))
(file-remote-p default-directory))
(setq fullname
(if (file-name-absolute-p fullname)
(concat (file-remote-p default-directory) fullname)
(expand-file-name fullname default-directory))))
(if (and fullname (not (or eshell-force-execution
(file-executable-p fullname))))
(while suffixes
(let ((try (concat fullname (car suffixes))))
(if (or (file-executable-p try)
(and eshell-force-execution
(file-readable-p try)))
(setq fullname try suffixes nil)
(setq suffixes (cdr suffixes))))))
(cond ((not (and fullname (file-exists-p fullname)))
(let ((name (or fullname file)))
(unless (setq fullname
(run-hook-with-args-until-success
'eshell-alternate-command-hook file))
(error "%s: command not found" name))))
((not (or eshell-force-execution
(file-executable-p fullname)))
(error "%s: Permission denied" fullname)))
(let (interp)
(unless no-examine-p
(setq interp (eshell-script-interpreter fullname))
(if interp
(setq interp
(cons (car (eshell-find-interpreter (car interp) args t))
(cdr interp)))))
(or interp (list fullname)))))))