busybox-w32 icon indicating copy to clipboard operation
busybox-w32 copied to clipboard

Behaviour difference for busybox path

Open ale5000-git opened this issue 2 years ago • 9 comments

C:/TEST $ PATH=""
C:/TEST $ which busybox
C:/TEST/busybox.exe
C:/TEST $ command -v busybox
busybox.exe
C:/TEST $ hash busybox || echo error
C:/TEST $ hash
C:/TEST $

which return full path. command -v return only filename without path. hash apparently do not fail, but it doesn't show anything.

ale5000-git avatar Apr 24 '22 08:04 ale5000-git

  • which returning the full path for busybox is a special exception: which busybox is used in the testsuite.
  • command adding the .exe extension is a bug which I'm looking into fixing now. This only happens if you have busybox.exe in your current directory.
  • In standalone shell mode BusyBox applets behave like shell built-ins so it's expected that hash won't report them. (From POSIX: "Utilities provided as built-ins to the shell shall not be reported by hash.")

rmyorston avatar Apr 24 '22 10:04 rmyorston

The latest prerelease should have a fix for the command -v issue.

rmyorston avatar Apr 24 '22 11:04 rmyorston

I have put the latest binary in 2 copies as busybox.exe and busybox_pre.exe in C:\TEST

I get this:

C:\TEST>busybox_pre.exe ash
C:/TEST $ PATH=".;$PATH"

C:/TEST $ which busybox_pre
./busybox_pre.exe
C:/TEST $ command -v busybox_pre
./busybox_pre.exe
C:/TEST $ hash busybox_pre
C:/TEST $ hash
./busybox_pre.exe

C:/TEST $ hash -r

C:/TEST $ which busybox
C:/TEST/busybox_pre.exe
C:/TEST $ command -v busybox
busybox
C:/TEST $ hash busybox
C:/TEST $ hash
C:/TEST $

Why can't I get the path with command -v busybox?

ale5000-git avatar Apr 24 '22 11:04 ale5000-git

Why can't I get the path with command -v busybox?

busybox_pre.exe includes a busybox applet which takes precedence over the busybox.exe binary.

rmyorston avatar Apr 24 '22 11:04 rmyorston

So this is intended, but for me it doesn't make sense, moreover it should at least match filename of the executable. If from busybox_pre.exe I search busybox.exe I cannot find it.

ale5000-git avatar Apr 24 '22 12:04 ale5000-git

Looks OK to me:

~ $ ./busybox_pre sh
~ $ export PATH=".;$PATH"
~ $ which busybox.exe
./busybox.exe
~ $ command -v busybox.exe
./busybox.exe
~ $

rmyorston avatar Apr 24 '22 12:04 rmyorston

Well, I guess this inconsistency (of virtual busybox applet) lies in upstream busybox.

ale5000-git avatar Apr 24 '22 13:04 ale5000-git

Reopening because I've made some relevant changes.

  • command -v now reports the full path when the applet name matches the running binary, similar to which.
  • which now only does the special magic for built-in applets when it's run directly from the shell. This makes it possible to revert to the standard behaviour of which (where it does a PATH lookup) by running it as, for example, env which busybox.

The example above, with the two binaries in the current directory, now does this:

C:\Users\rmy>.\busybox_pre sh
~ $ export PATH=".;$PATH"
~ $
~ $ which busybox_pre
./busybox_pre.exe
~ $ command -v busybox_pre
./busybox_pre.exe
~ $
~ $ which busybox
C:/Users/rmy/busybox_pre.exe
~ $ command -v busybox
C:/Users/rmy/busybox_pre.exe
~ $
~ $ env which busybox
./busybox.exe
~ $

Since command is a shell built-in, not an applet, the env trick doesn't work for it.

rmyorston avatar May 01 '22 10:05 rmyorston

I'm testing it now, it seems really good and really beyond my expectations. Thanks a lot.

ale5000-git avatar May 06 '22 16:05 ale5000-git

Closing this issue as the latest release should have the necessary fixes.

rmyorston avatar Nov 10 '22 13:11 rmyorston