使用Emacs TRAMP和不提供/ bin/sh的ssh服务器?

Rya*_*son 9 emacs ssh android tramp

我试图使用Emacs TRAMP通过ssh访问未提供的服务器上的文件/bin/sh,因此当我尝试连接时出现以下错误:

env: can't execute '/bin/sh': No such file or directory
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉TRAMP远程shell在哪个服务器?("服务器"是一个系留Android手机,所以请进入/system/bin/sh.)

phi*_*ils 6

另请参见tramp-methods变量的docstring .这部分看起来值得注意:

  • tramp-remote-shell
    这指定了要在远程主机上使用的shell.这必须是一个类似Bourne的shell.通常没有必要将其设置为"/ bin/sh"以外的任何值:Tramp想要使用一个可以进行波形扩展的shell,但它可以搜索它.另请注意,所有Unixen上都存在"/ bin/sh",对于您决定使用的值,这可能不正确.你被警告了.

编辑:

所以这里有一种方法可以创建一个基于现有方法的新方法(在本例中为"scpc"),然后为自定义方法提供一个不同的远程shell:

(require 'tramp)
(let* ((base-method (cdr (assoc "scpc" tramp-methods)))
       (new-method (copy-tree base-method))
       (rshell (assq 'tramp-remote-shell new-method)))
  (setcdr rshell "/system/bin/sh")
  (add-to-list 'tramp-methods (cons "android" new-method)))
Run Code Online (Sandbox Code Playgroud)

请注意,在Emacs 23(Tramp 2.1.20)中,此属性已命名tramp-remote-sh.在Emacs 24(Tramp 2.2.3-24.1)中,它已被更改为tramp-remote-shell.

我猜你可以默认使用这个方法为你指定的主机:

(add-to-list
 'tramp-default-method-alist
 (list "\\`myhost\\'" nil "android"))
Run Code Online (Sandbox Code Playgroud)