3

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?

Hooked
  • 1,343
  • 3
  • 17
  • 24

3 Answers3

5
  • 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
    
jimmij
  • 46,064
  • 19
  • 123
  • 136
1

You could always just use a simple loop:

for f in *.md; do aspell check "$f"; done
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Doorknob
  • 2,993
  • 1
  • 16
  • 18
  • 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
0

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.

badbishop
  • 101
  • 1