The characters '?' and '*' are treated as wildcards on the command line in both Microsoft Windows and Unix. In both cases the wildcards are expanded by matching against filenames, a process known as 'globbing'. A '?' matches a single character and '*' matches multiple characters.
In Unix wildcards are expanded by the shell and any matching filenames
are passed as arguments to the program being run.
In Windows the command intepreter passes unexpanded arguments to
the program and the C runtime library performs the expansion.
In both cases the expansion happens before the
function of the program is executed.
These different mechanisms for globbing result in a difficulty for BusyBox on Windows. BusyBox contains a Unix-style shell, which performs Unix-style globbing on the command line, but busybox.exe is a Windows command line program, which would normally have globbing performed by the C runtime.
When a command is run from the BusyBox shell the shell expands any wildcards. If the command is one of those implemented by BusyBox the busybox.exe binary is executed again. If any wildcards weren't expanded by the shell (either because they failed to match or because they were escaped by the user) they will be passed to this second invocation of BusyBox. If busybox.exe were to expand these wildcards in might result in unexpected behaviour.
To avoid this difficulty busybox.exe, by default, is built with globbing in the C runtime disabled. When BusyBox is run from the Windows command prompt it can behave in ways that don't conform to expectations:
C:\Users\rmy>busybox ls * ls: *: No such file or directory C:\Users\rmy>copy busybox.exe ls.exe 1 files(s) copied. C:\Users\rmy>ls * ls: *: No such file or directory
However, this is necessary for the shell to work properly. Consider:
~ $ cat <<EOF | grep '*' > hello world o > hello stars * > EOF hello stars * ~ $By putting the asterisk in quotes the user has prevented the shell from expanding it. If busybox.exe behaved like a normal Windows command line program it would expand the '*' when invoked as
grep. This is not what the user intended.
(As it happens, the problem only really affects pipelines. In most other
cases programs run by the BusyBox shell are invoked using
forkshell mechanism which bypasses the command line.)
I use the BusyBox shell far more often than I use BusyBox commands from the Windows command prompt. To ensure that the shell works properly busybox.exe has globbing by the C runtime disabled. If you don't like this arrangement it's possible to change the default at compile-time. The relevant setting is:
Settings ---> Allow busybox.exe to expand wildcards
It would be nice if this could be a run-time rather than compile-time option. However, that would require the co-operation of the C runtime: it's not something that can be done in BusyBox itself.
For those who need it a prebuilt 32-bit binary with Windows wildcards enabled is available: busybox_glob.exe. This may not be updated as frequently as the main build.
The latest executable is 443,392 bytes in size. Its sha256sum is:
6219611f61fe6ceac403c96ffcc149073d5adf2cf5477d3d1da3ab781f43c5ceThis key has been used to generate the PGP signature file busybox_glob.exe.sig.