Search code examples
pythonshellxonsh

how to use -exec on the find command with xonsh?


In xonsh I can run a find command like this:

find @(str(path)) -iname "log.txt"

Where path is a pathlib.Path object.

However, I don't understand how to use the -exec and -execdir options on find:

find @(str(path)) -iname "log.txt" -execdir pwd {} \;

This results in the error:

SyntaxError: <xonsh-code>:1:5: ('code: @(',)

I reviewed Tutorial — xonsh 0.10.1.dev5.dev5 documentation and tried @$(...) and numerous other variations without any success.

Edit: this version

find @(str(path)) -iname "log.txt" -execdir pwd '{}' \;

gives this error:

find: missing argument to `-execdir'

Solution

  • Just adding the answer here for future reference:

    This bash

    find ~/.local/lib/python3.8/ -iname "*ygments*pyc" -exec ls -ahtlr {} \;
    

    becomes this xonsh it seems...

    find ~/.local/lib/python3.8 -iname "*ygments*pyc"  -exec ls -ahltr "{}" ";"
    

    Though this also seem to work :-D :

     for i in !(find ~/.local/lib/python3.8 -iname "*ygments*pyc"):
         ls -ahtlr @(i.strip())