首页 > 解决方案 > MobaXterm Busybox 奇怪的设置

问题描述

我正在使用 MobaXterm 便携版。我发现了一个奇怪的设置,总结在这里。

外部命令/bin工作正常。例如,/bin/ssh.exessh可以确定。

内部命令是

  1. “重定向”到busybox,如

    $ which cat
    /bin/cat
    $ ll /bin/cat
    lrwxrwxrwx    1 USER001  UsersGrp        16 Jul 24 07:42 /bin/cat -> /bin/busybox.exe
    
  2. 同时别名为显然不存在的文件。

    $ type cat
    cat is aliased to `/bin/cat.exe'
    

这些别名显然优先于 PATH 中的文件,因此这些命令不起作用。

$ cat myfile
bash: /bin/cat.exe: No such file or directory

如果我取消别名,cat不寻找/bin/cat.exebut for /bin/busybox.exe,一切都“恢复正常”。

$ unalias cat
$ cat myfile
Hello world
...

如何获得正常行为(没有别名或存在别名目标)? 我的意思是不要在 中写我自己的 unaliases .bashrc,这不应该是必需的。此外,也许我会破坏一些东西。

为什么 MobaXterm 会设置这样的东西?

PS:在初始状态下,偶ls也不行,同理。但是ll有效,因为

$ type ll
ll is aliased to `_bbf ls -l'
$ type _bbf
_bbf is a function
...

标签: mobaxterm

解决方案


我怎样才能得到正常的行为?

解决方法:

  1. unalias手工ing,所以/bin/busybox.exe实际使用。
    下面我为此添加一个脚本。

  2. 当临时目录可用时从临时目录复制.exe文件root,因此使用外部版本。

为什么 MobaXterm 会设置这样的东西?

当不使用持久根 (/) 目录时,将获得

$ which cat
/bin/cat
$ ll /bin/cat
-rwxr-xr-x 1 RY16205 UsersGrp 49703 jul. 28 07:12 /bin/cat
$ type cat
cat is aliased to `/bin/cat.exe'
$ ll /bin/cat.exe
-rwxr-xr-x 1 USER001 UsersGrp 49703 jul. 28 07:12 /bin/cat.exe
$ cat myfile
Hello world
...
$ unalias cat
$ type cat
cat is hashed (/bin/cat)
$ cat myfile
Hello world
...

所以两者中cat的任何一个都可以工作(内部busybox和外部版本;我不知道它们是否完全相同)。这是因为/bin指向C:\Users\user001\AppData\Local\Temp\Mxt108\bin并且cat.exe存在。

但是当使用持久根 (/) 目录时,/bin指向<Persistent root (/) directory\bin,并且cat.exe不会在那里创建。root一旦 MXT 关闭 ,以前的临时目录就会被删除。所以这可能是 MobaXterm 的配置错误。 如果是这样,唯一的选择似乎是一种解决方法,如上所述。


反锯齿脚本:

#!/bin/bash

export ROOTDIR_WIN=$(cygpath -wl /)
if [[ ${ROOTDIR_WIN##*\\} == "Mxt108" ]] ; then
    # Not using a Persistent root dir. Do not need to unalias. 
    echo "Not using a Persistent root dir. Do not need to unalias."
else
    # Using a Persistent root dir. Need to unalias.
    exe_linux_list="bash busybox chmod cygstart cygtermd cygwin-console-helper dircolors dwm_w32 echo grep ls MoTTY ssh ssh-pageant test twm_w32 wc xkbcomp_w32 XWin_MobaX"

    for exe_linux in ${exe_linux_list} ; do
        if [[ $(type -t ${exe_linux}) == "alias" ]] ; then
            #type ${exe_linux}
            unalias ${exe_linux}
        fi
    done
fi

推荐阅读