Function: executable-find

executable-find is a byte-compiled function defined in files.el.gz.

Signature

(executable-find COMMAND &optional REMOTE)

Documentation

Search for COMMAND in exec-path(var)/exec-path(fun) and return the absolute file name.

Return nil if COMMAND is not found anywhere in exec-path(var)/exec-path(fun). If REMOTE is non-nil, search on the remote host indicated by default-directory instead.

Other relevant functions are documented in the file group.

Probably introduced at or before Emacs version 27.1.

Shortdoc

;; file
(executable-find "ls")
    e.g. => "/usr/bin/ls"

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun executable-find (command &optional remote)
  "Search for COMMAND in `exec-path' and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'.  If
REMOTE is non-nil, search on the remote host indicated by
`default-directory' instead."
  (if (and remote (file-remote-p default-directory))
      (let ((res (locate-file
                  command
                  (mapcar
                   (lambda (x) (concat (file-remote-p default-directory) x))
                   (exec-path))
                  exec-suffixes 'file-executable-p)))
        (when (stringp res) (file-local-name res)))
    ;; Use 1 rather than file-executable-p to better match the
    ;; behavior of call-process.
    (let ((default-directory (file-name-quote default-directory 'top)))
      (locate-file command exec-path exec-suffixes 1))))