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?

  • 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
| improve this answer | |

You could always just use a simple loop:

for f in *.md; do aspell check "$f"; done
| improve this answer | |
  • 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

I agree, using xargs with find is redundant, but if the input comes from something else and you have to use xargs, just use -o:

grep -rl 'draft: false' | xargs -o -n1 aspell check --sug-mode=slow

man xargs has this to say:

-o Reopen stdin as /dev/tty in the child process before executing the command. This is useful if you want xargs to run an interactive application.

| improve this answer | |

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.