android - 将 Emacs TRAMP 与不提供/bin/sh 的 ssh 服务器一起使用?

标签 android emacs ssh tramp

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

env: can't execute '/bin/sh': No such file or directory

有什么方法可以告诉 TRAMP 该服务器的远程 shell 在哪里? (“服务器”是一个系留的 Android 手机,所以 sh 在 /system/bin/sh。)

最佳答案

另请参阅 tramp-methods 变量的文档字符串。这部分看起来值得注意:

  • tramp-remote-shell
    This specifies the shell to use on the remote host. This MUST be a Bourne-like shell. It is normally not necessary to set this to any value other than "/bin/sh": Tramp wants to use a shell which groks tilde expansion, but it can search for it. Also note that "/bin/sh" exists on all Unixen, this might not be true for the value that you decide to use. You Have Been Warned.

编辑:

所以这里有一种方法可以基于现有方法(本例中为“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)))

请注意,在 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"))

关于android - 将 Emacs TRAMP 与不提供/bin/sh 的 ssh 服务器一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10629439/

相关文章:

git - 使用 ssh-agent 调用 docker-compose

java - 你如何阻止 Proguard 删除类型参数?

java - Android 特定的 OnItemClick Intent

emacs - 内置 Emacs Lisp 库中此函数的名称?

emacs - 分离并重新连接到 Emacs 服务器

bash - sed命令无法通过SSH使用

git - ssh-keygen 使用 sshfp 生成 key

android - 如何在 Activity 开始时显示选项菜单

android - 如何在android中关闭wifi的情况下获取wifi配置的网络?

c++ - 如何在 Vi 和 Emacs 中使用相同缩进样式的 C++ 代码?