1

I'm trying to spell check all the *.md files in my current directory but the following command fails:

>> find . -maxdepth 1 -name "*.md" | xargs -I {} aspell check {}
xargs: aspell: exited with status 255; aborting

I'm assuming this is because aspell requires stdin to interact with the user and somehow xargs doesn't provide it. I found a hack on Twitter,

find . -maxdepth 1 -name "*.md" | xargs -n 1 xterm -e aspell check

but this opens up a new xterm each time. How can I get my original command to work as if I were to individually run aspell on the results of my find command?

3
  • You don't need xargs at all, just use exec option:

    find . -maxdepth 1 -name "*.md" -exec aspell check {} \;
    
  • And just in case you, or any future reader, will really need to use xargs - you can do that by spawning new shell and taking standard input from terminal (/dev/tty):

    find . -maxdepth 1 -name "*.sh" | xargs -n1 sh -c 'aspell check "$@" < /dev/tty' aspell
    
1

You could always just use a simple loop:

for f in *.md; do aspell check "$f"; done
  • That works, but for pedagogic purposes is it possible to do it with find without spawning a new xterm? – Hooked Jan 25 '15 at 17:53
  • @Hooked Apparently, yes (see jimmij's answer, which is more extensible if you need more precise criteria for finding the files). – Doorknob Jan 25 '15 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.