Thanks for the explanations! Now I understand. I thought it was related to the search results somehow... I didn't consider the local argument expansion.
2018-02-08 5:23 GMT+01:00 Robert Thompson <[email protected]>: > This is because the wildcard argument to -iname needs *not* to be > expanded by the shell. It needs to be passed to find as a literal > unexpanded string still containing wildcards. Usually this means > single-quoting. > > for example, > find . -iname '*data' > > > > > The -iname takes a single argument, and if the *shell* expands the > wildcard, the arguments find sees will be out of sync with > expectations, resulting in an unexpected argument, or even unintended > side effects, if the wildcard matched a file named '-delete' or > something... > > > one easy way of debugging this general kind of error is to add echo to > the front of your commandline, so you can see the results. > > find . -iname '*.foo' > > becomes > > echo find . -iname '*.foo' > > if it prints > > find . -iname *.foo > > everything is good. If it prints > > find . -iname a.foo b.foo c.foo > > you have a problem. In most cases double quotes are okay, but single > quotes are safe. > > Imagine someone really hates you and creates a filename that is > literally $( rm -rf ${HOME} ) or something similar. doublequoted, the > shell will still execute the rm so that it can expand the $( ) > variable with the stdout of the rm. Singlequoted, no expansion occurs. > > > > > On 2/7/18, darken <[email protected]> wrote: > > I just noticed the following find applet behavior with regards to > > wildcards. > > I don't think it's a bug as it shows in all find applets, but I'm puzzled > > by what is happening. > > > > It seems that when using wildcards and the search results contain a > > wildcard match that contains a dash, then find uses the result as > argument > > option? Why? > > > > ~Matthias > > > > ``` > > sailfish:/sdcard $ find --version > > toybox 0.7.4-android > > sailfish:/sdcard $ find . -iname *data > > find: bad arg 'sleep-data' > > 1|sailfish:/sdcard $ find . -iname "*data" > > ./Android/data > > ./data > > ./sleep-data > > ./Documents/sleep-data > > sailfish:/storage/emulated/0 # find . -iname *droid > > ./Android > > > > > > sailfish:/storage/emulated/0 # /data/local/tmp/busybox-armv6l find . > -iname > > *data > > find: unrecognized: sleep-data > > BusyBox v1.26.2 (2017-01-11 08:43:16 UTC) multi-call binary. > > > > > > darken@greendns:~/test$ find --version > > find (GNU findutils) 4.7.0-git > > darken@greendns:~/test$ mkdir -p Android/data > > darken@greendns:~/test$ mkdir data > > darken@greendns:~/test$ mkdir sleep-data > > darken@greendns:~/test$ mkdir -p Documents/sleep-data > > darken@greendns:~/test$ find . -iname *data > > find: paths must precede expression: sleep-data > > ``` > > >
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
