4

I am using MobaXterm portable. I found a strange setup, summarized here.

External commands in /bin work fine. E.g., with /bin/ssh.exe I can ssh ok.

Internal commands are

  1. "redirected" to busybox, as

    $ which cat
    /bin/cat
    $ ll /bin/cat
    lrwxrwxrwx    1 USER001  UsersGrp        16 Jul 24 07:42 /bin/cat -> /bin/busybox.exe
    
  2. at the same time aliased to files that apparently do not exist.

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

These aliases apparently take precedence over files in PATH, so the commands do not work.

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

If I unalias, cat does not look for /bin/cat.exe but for /bin/busybox.exe, and everything is "back to normal".

$ unalias cat
$ cat myfile
Hello world
...

How can I get normal behaviour (either without aliases or with the presence of the alias targets)? I mean not to write my own unaliases in .bashrc, this shouldn´t be needed. Moreover, perhaps I would be breaking something.

Why would MobaXterm setup things like this?

PS: In the initial state, even ls does not work, for the same reason. But ll works, since

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

3 Answers3

1

How can I get normal behaviour?

Workarounds:

  1. unaliasing by hand, so /bin/busybox.exe is actually used.
    Below I add a script for that.

  2. Copying .exe files from the temporary root dir when it is available, so the external versions are used.

Why would MobaXterm setup things like this?

When not using a Persistent root (/) directory, this is obtained

$ 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
...

So any of the two cats work (internal busybox and external versions; I do not know if they are exactly the same). This is because /bin points to C:\Users\user001\AppData\Local\Temp\Mxt108\bin and cat.exe is there.

But when using a Persistent root (/) directory, /bin points to <Persistent root (/) directory\bin, and cat.exe is not created there. The former temporary root dir is removed as soon as MXT is closed. So this is probably a configuration error from MobaXterm. If so, the only option seems a workaround, as above.


Script for unaliasing:

#!/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
1

On my MobaXterm system, /etc/profile sources /etc/baseprofile which includes aliases for all of these sorts of things, i.e.

alias "cat"="_bbf cat"

and checking that from my command prompt yields what I would expect:

$ type cat
cat is aliased to `_bbf cat'

Have you changed your system somehow so that /etc/baseprofile is not being sourced? Or have you changed /etc/baseprofile?

It also appears that you've installed the regular GNU Coreutils package, as I don't have a /bin/cat.exe.

$ ll /bin/cat.exe
ls: /bin/cat.exe: No such file or directory

Perhaps that's where your problem started but the _bbf function is supposed to handle that. Which again leads me to the belief that you've changed /etc/baseprofile somehow.

SeeJayBee
  • 1,188
  • 1
  • 8
  • 22
0

At most time, it is cool. This error maybe caused by wrong path match of cat.exe.

As for me, when I run git log, the same error message comes out. It is due to PATH variable. There are two dirs and both of them contain git.exe. One of them is half-done with a small size. And Mobaxterm choose it. :D

I confirm this by run which git and it will give the actual path out.

I fix it by

alias git='/drives/C/Program\ Files/Git/mingw64/bin/git.exe'

The following is my dirs.

├─cmd
│      git-gui.exe
│      git-lfs.exe
│      git.exe                              # oops
│      gitk.exe
│      start-ssh-agent.cmd
│      start-ssh-pageant.cmd
├─mingw64
│  ├─bin
│  │      git-upload-pack.exe
│  │      git.exe                           # the right one
W.Perrin
  • 4,217
  • 32
  • 31