一起使用 find 和 aspell

Hoo*_*ked 3 find aspell stdin

我正在尝试对*.md当前目录中的所有文件进行拼写检查,但以下命令失败:

>> find . -maxdepth 1 -name "*.md" | xargs -I {} aspell check {}
xargs: aspell: exited with status 255; aborting
Run Code Online (Sandbox Code Playgroud)

我假设这是因为aspell需要stdin与用户交互并且以某种方式xargs不提供它。我在 Twitter 上发现了一个黑客

find . -maxdepth 1 -name "*.md" | xargs -n 1 xterm -e aspell check
Run Code Online (Sandbox Code Playgroud)

但这每次都会打开一个新的 xterm。如何让我的原始命令工作,就像我要单独运行aspell我的 find 命令的结果一样?

jim*_*mij 5

  • 您根本不需要xargs,只需使用exec选项:

    find . -maxdepth 1 -name "*.md" -exec aspell check {} \;
    
    Run Code Online (Sandbox Code Playgroud)
  • 以防万一您或任何未来的读者真的需要使用xargs- 您可以通过生成新 shell 并从终端 ( /dev/tty)获取标准输入来做到这一点:

    find . -maxdepth 1 -name "*.sh" | xargs -n1 sh -c 'aspell check "$@" < /dev/tty' aspell
    
    Run Code Online (Sandbox Code Playgroud)