Closed SnDream closed 5 months ago
Wildcards aren't expanded in redirections in BusyBox ash, dash or busybox-w32 ash.
On Linux:
$ busybox sh
~ $ mkdir iss391
~ $ cd iss391
~/iss391 $ touch abc.txt
~/iss391 $ echo test >a*.txt
~/iss391 $ ls -l
total 4
-rw-r--r--. 1 rmy rmy 0 Mar 25 15:10 abc.txt
-rw-r--r--. 1 rmy rmy 5 Mar 25 15:10 'a*.txt'
~/iss391 $ cat a*.txt
test
~/iss391 $
$ dash
$ mkdir iss391_dash/
$ cd iss391_dash/
$ touch abc.txt
$ echo test >a*.txt
$ ls -l
total 4
-rw-r--r--. 1 rmy rmy 0 Mar 25 15:08 abc.txt
-rw-r--r--. 1 rmy rmy 5 Mar 25 15:08 'a*.txt'
$ cat a*.txt
test
$
The observed behaviour with busybox-w32 ash on Windows arises because *
isn't allowed in filenames so the file a*.txt
can't be created.
Other shells (e.g. bash, ksh) do expand wildcards in redirections.
According to POSIX, pathname expansion in redirection is optional:
If the redirection operator is "<<" or "<<-", the word that follows the redirection operator shall be subjected to quote removal; it is unspecified whether any of the other expansions occur. For the other redirection operators, the word that follows the redirection operator shall be subjected to tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion shall not be performed on the word by a non-interactive shell; an interactive shell may perform it, but shall do so only when the expansion would result in one word.
Oh, that makes sense.
When the redirected destination filename has a wildcard character, busybox-w32 cannot properly find the destination file corresponding to the wildcard character.
For busybox under Linux, the file can be found.